您如何在SQL Server 2008中进行分页?
3 回答
互换的青春
TA贡献1797条经验 获得超6个赞
您可以尝试类似
DECLARE @Table TABLE(
Val VARCHAR(50)
)
DECLARE @PageSize INT,
@Page INT
SELECT @PageSize = 10,
@Page = 2
;WITH PageNumbers AS(
SELECT Val,
ROW_NUMBER() OVER(ORDER BY Val) ID
FROM @Table
)
SELECT *
FROM PageNumbers
WHERE ID BETWEEN ((@Page - 1) * @PageSize + 1)
AND (@Page * @PageSize)
慕田峪7331174
TA贡献1828条经验 获得超13个赞
您可以使用ROW_NUMBER():
返回结果集分区中一行的序号,从每个分区中第一行的1开始。
例:
WITH CTEResults AS
(
SELECT IDColumn, SomeField, DateField, ROW_NUMBER() OVER (ORDER BY DateField) AS RowNum
FROM MyTable
)
SELECT *
FROM CTEResults
WHERE RowNum BETWEEN 10 AND 20;
- 3 回答
- 0 关注
- 901 浏览
添加回答
举报
0/150
提交
取消