Sql三种分页方法
--分页三种方法
--第一种 ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs 大于pagesize*pageindex,少于等于pagesize*(pageindex+1) --效率最高
SELECT * FROM Sys_User AS A
LEFT JOIN
(
SELECT ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs ,ID FROM dbo.Sys_User --效率 次之
) AS B ON A.ID = B.ID
WHERE B.indexs > 0 AND B.indexs <= 10
--第二种 Not in + select
SELECT TOP 10 * FROM dbo.Sys_User
WHERE ID NOT IN (SELECT TOP 10 ID FROM dbo.Sys_User)
--第三种 借助游标内置方法,消耗内存,OFFSET 跳过10条取接下来10条 --效率最差
SELECT *
FROM Sys_User
ORDER BY ID
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;