如何在Access查询中选择前10名? [英] How to select top 10 in Access query?

查看:286
本文介绍了如何在Access查询中选择前10名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Access 数据库表有 2 列:名称和价格.我想做一个选择前 10 个最高价格的查询.这个怎么做?谢谢.

My Access database table has 2 columns: name and price. I want to do a query that select the top 10 highest prices. How to do this? Thanks.

推荐答案

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

这篇关于如何在Access查询中选择前10名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆