SQL Server使用ROW_NUMBER进行快速分页查询

 

DECLARE @pageSize INT
DECLARE @pageIndex INT

 

--第4页,每页显示10条数据
SET @pageSize = 10
SET @pageIndex = 4

SELECT * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY Created_Time ASC) AS 'RowNumber', * FROM dbo.COM_UserInfo
) AS UserInfo
WHERE RowNumber BETWEEN ( ( ( @pageIndex - 1 ) * @pageSize ) + 1 ) AND ( @pageIndex * @pageSize )

 

posted @ 2018-03-19 17:34  AZRNG  阅读(153)  评论(0编辑  收藏  举报