直接上代码 --top not in方式 select top 条数 * from tablename where Id not in (select top 条数*页数 Id from tablename) --ROW_NUMBER() OVER()方式 select * from ( select *, ROW_NUMBER() OVER(Order by Id ) AS RowNumber from tablename ) as b *条数 and 页数*条数 --offset fetch…
USE tempdb GO SET NOCOUNT ON --创建表结构 IF OBJECT_ID(N'ClassB', N'U') IS NOT NULL DROP TABLE ClassB GO ), CreateDate DATETIME, AID INT, Status INT) CREATE INDEX IDX_CreateDate ON ClassB(CreateDate) CREATE INDEX IDX_AID ON ClassB(AID) GO --插入测试数据 DECLARE…
第一种:ROW_NUMBER() OVER()方式 select * from ( select *, ROW_NUMBER() OVER(Order by ArtistId ) AS RowId from ArtistModels ) as b where RowId between 10 and 20 ---where RowId BETWEEN 当前页数-1*条数 and 页数*条数--- 执行结果是: 第二种方式:offset fetch next方式(SQL2012以上的版本才支持:推…