分页SQL
-
Top(最慢,not in 数据庞大,而且不走索引,但支持性好,基本sql都支持)
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
-
Row_Number(Sql2004以上才可以用效率挺好)
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)
-
Offset Fetch (性能最高,sql2012才支持)
select * from Customers order by CustomerID desc offset ((@pageindex - 1) * @pagesize) rows fetch next @pagesize rows only