首页 > 代码库 > 分页的三种方式
分页的三种方式
分页的三种方式
临时表 效率最差:
DECLARE @indextable table(id int identity(1,1) PRIMARY KEY,nid int);
INSERT INTO @indextable(nid) SELECT Id FROM FlightSpecialPrice AS l WITH (readpast) WHERE 1=1 ;--{0} {1};
SELECT recrowcount=@@ROWCOUNT;
SELECT * FROM @indextable as i
JOIN FlightSpecialPrice AS t
WITH (readpast) ON (i.nid = t.Id AND i.id > 20 AND i.id < 1000) ORDER BY i.Id; Top 效率次于Row_Number:
SELECT TOP 1000 *
FROM FlightSpecialPrice
WHERE (ID NOT IN
(SELECT TOP 20 id
FROM FlightSpecialPrice
ORDER BY id))
ORDER BY IDrow_number() 效率最高:
select * from (
SELECT ROW_NUMBER() over(order by id ) num,*
FROM FlightSpecialPrice
) res
where num between 21 and 1020 来自为知笔记(Wiz)
分页的三种方式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。