SqlServer 第31到第40条记录的各种玩法
--两次对表A查询效率较低
select top 10 *
from A
where ID not in (select top 30 ID from A)
--外层查询没有对表A查询,效率大有提高
select top 10 *
from (select top 40 * from A order by ID) as t
order by t.ID desc
--ROW_NUMBER()函数效率更高,sqlserver2005以及以上版本中才可以使用
select *
from (select ROW_NUMBER() over(order by ID) as ‘sequence‘,A.* from A ) as t
where t.sequence between 31 and 40
SELECT * FROM A Order by ID OFFSET 30 ROWS FETCH NEXT 10 ROWS ONLY
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。