项目整理复习一:SQL高效分页存储过程

declare @pageStart varchar(20)

declare @pageEnd varchar(20)

set @pageStart= 1

set @pageEnd= 30

select * from (select *, row_number() over(order by createTime desc) as rowIndex from [TABLE] ) tbAll where tbAll.rowIndex>=@pageStart and tbAll.rowIndex<=@pageEnd order by tbAll.createTime desc

 

关键在 row_number() over(order by createTime desc) as rowIndex from [TABLE]

你可能感兴趣的:(存储过程)