我最喜欢的SQL分页查询方法
时间:2021-07-01 10:21:17
帮助过:3人阅读
USE AdventureWorks2012;
2 GO
3
4 DECLARE @PageSize int = 100,
@PageNumber int = 3;
5
6 WITH Product_CTE
7 AS
8 (
9 SELECT Name
10 ,ProductNumber
11 ,StandardCost
12 ,ListPrice
13 ,SellStartDate
14 ,ROW_NUMBER()
OVER(
ORDER BY ProductID)
AS RowNumber
15 ,
COUNT(
*)
OVER()
AS TotalCount
16 FROM Production.Product
17 )
18 SELECT *
19 FROM Product_CTE
20 WHERE RowNumber
BETWEEN @PageSize * (
@PageNumber - 1)
+ 1 AND @PageSize * @PageNumber;
我最喜欢的SQL分页查询方法
标签: