数据库
首页 > 数据库> > sqlserver offset的坑

sqlserver offset的坑

作者:互联网

SELECT id,dtime FROM dbo.TestTab
ORDER BY id
OFFSET 1 ROWS FETCH NEXT 100 ROWS ONLY
 
SELECT id,dtime FROM (
    SELECT ROW_NUMBER()OVER(ORDER BY id ASC) AS orderid,id,dtime
    FROM dbo.TestTab
) TAB
WHERE orderid BETWEEN 1 AND 100
ORDER BY orderid
 

这里要order by 主键,不会只能取到部分数据。

标签:orderid,TestTab,dtime,sqlserver,id,offset,ORDER,SELECT
来源: https://www.cnblogs.com/Insist-Y/p/15671621.html