There is TOP command. However, if we want not to use the TOP command what would be the best way of selecting top 5 records?
有TOP命令。但是,如果我们不想使用TOP命令,那么选择前5条记录的最佳方法是什么?
SELECT TOP 5 * FROM table1;
1 个解决方案
#1
1
A simple but very inefficient approach:
一种简单但非常低效的方法:
select * from
(select t.*,
(select count(*)
from table1 c
where c.order_column <= t.order_column) top_n
from table1 t) sq
where top_n <= 5
#1
1
A simple but very inefficient approach:
一种简单但非常低效的方法:
select * from
(select t.*,
(select count(*)
from table1 c
where c.order_column <= t.order_column) top_n
from table1 t) sq
where top_n <= 5