1、Top+Not In,支持SqlServer所有版本
···
create proc Tops @pageindex int,@pagesize int
AS
BEGIN
select top (@pagesize) * from Customers where CustomerID not in
(select top ((@pageindex - 1)* @pagesize) CustomerID from Customers order by CustomerID DESC) order by CustomerID DESC
END
2、Row_Number(),支持SqlServer2005+版本
···
create proc RowNumber @pageindex int,@pagesize int
AS
BEGIN
select * from
(select ROW_NUMBER() OVER(order by CustomerID desc) as px,* from Customers) as a
where a.px between ((@pageindex - 1)* @pagesize + 1) and (@pageindex*@pagesize)
END
···
3、Offset Fetch,支持SqlServer2012+版本
···
create proc Offset_Fetch @pageindex int,@pagesize int
AS
BEGIN
select * from Customers order by CustomerID desc
offset ((@pageindex - 1) * @pagesize) rows
fetch next @pagesize rows only
END
···
性能对比:3>2>1