我想显示表格中的前3条记录,请帮助我 [英] i want to show top 3 record from table,pls help me
问题描述
亲爱的所有
我想显示前3条记录
我有一张桌子,其中2个字段ID和cat_type
我想显示cat_type列中的前3条记录
dear all
i want to show top 3 record
i have a table where 2 field ID and cat_type
i want to show top 3 record from cat_type column
select top 3 ID , cat_type from catagory
我使用了此查询,但是此查询显示了cat_type列中的所有记录
我该如何帮助我
i used this query but this query show all the record from cat_type column
how can i do pls help me
推荐答案
尝试
SELECT TOP 3 cat_type FROM catagory
如果您的数据库是MSSQL,请尝试此
Select Top 3 ID, cat_type from category
或
如果您的数据库是MYSQL,请尝试此
SELECT ID,cat_type FROM category LIMIT 3
如果无法正常工作,请通知我
谢谢
if your database is MSSQL try this
Select Top 3 ID, cat_type from category
or
if your database is MYSQL try this
SELECT ID,cat_type FROM category LIMIT 3
if not working please let me know
Thanks
在查询中将TOP
与ORDER BY
子句一起使用
如果要按降序显示基于ID的TOP 3条记录,
UseTOP
withORDER BY
clause in your query
If you want display TOP 3 records based on ID by descending order,
SELECT TOP 3 ID, cat_type FROM catagory ORDER BY ID DESC
或者如果您想按升序显示基于ID的前3条记录,
or if you want display TOP 3 records based on ID by ascending order,
SELECT TOP 3 ID, cat_type FROM catagory ORDER BY ID ASC
如果要按降序显示基于cat_type的TOP 3条记录,
If you want display TOP 3 records based on cat_type by descending order,
SELECT TOP 3 ID, cat_type FROM catagory ORDER BY cat_type DESC
或者如果您想按升序显示基于cat_type的TOP 3条记录,
or if you want display TOP 3 records based on cat_type by ascending order,
SELECT TOP 3 ID, cat_type FROM catagory ORDER BY cat_type ASC
根据您的要求使用查询.
编辑
-------------------------------------------------- -------------
如果您只想显示cat_type列,请尝试如下所示
Use the query based on your requirement.
EDIT
---------------------------------------------------------------
If you want to display only cat_type column then try like below
SELECT TOP 3 cat_type FROM catagory ORDER BY cat_type DESC
如果您仍然不清楚,请告诉我们您想要什么输出?在表格结构中包含样本数据.并显示您想要的示例输出.让我知道.
If still you are not clear then please show us what output do you want? Include the table structure with sample data. And show sample output which do you want. Let me know.
这篇关于我想显示表格中的前3条记录,请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!