使用 TOP 的示例
从 SALES 表返回任意 10 个行。由于未指定 ORDER BY 子句,因此该查询返回的行集是不可预测的。
select top 10 * from sales;
以下查询具有相同的功能,但使用的是 LIMIT 子句而非 TOP 子句:
select * from sales limit 10;
返回 SALES 表中的前 10 行,以降序顺序按 QTYSOLD 列排序。
select top 10 qtysold, sellerid from sales order by qtysold desc, sellerid; qtysold | sellerid --------+---------- 8 | 518 8 | 520 8 | 574 8 | 718 8 | 868 8 | 2663 8 | 3396 8 | 3726 8 | 5250 8 | 6216 (10 rows)
返回 SALES 表中的前两个 QTYSOLD 和 SELLERID 值(按 QTYSOLD 列排序):
select top 2 qtysold, sellerid from sales order by qtysold desc, sellerid; qtysold | sellerid --------+---------- 8 | 518 8 | 520 (2 rows)