且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Access查询中选择前10名?

更新时间:2023-01-29 23:21:42

select top 10 Name, Price
from MyTable
order by Price desc

更新:@Remou指出:

"Access SQL 选择匹配项,因此它将选择所有带有相同的最高价格,即使这包括超过 10 条记录.这解决方法是按价格和唯一字段(列)排序."

"Access SQL selects matches, so it will select all items with the same highest prices, even if this includes more than 10 records. The work-around is to order by price and a unique field (column)."

因此,如果您有一个唯一的产品代码列,请像这样添加:

So, if you have a unique product code column, add like so:

select top 10 Name, Price
from MyTable
order by Price desc, UniqueProductCode desc