SQL Server单条sql实现分页和总行数
SELECT
CustomerId AS customerId,
Phone AS userMobile,
Name AS userName,
FirstOrderTime AS firstOrderTime,
LatestOrderTime AS lastestOrderTime,
CustomerLevel AS customerLevel,
Call400Count AS call400Count,
OnlineOrderCount AS onlineOrderCount,
CityId AS cityId,
CityName AS cityName,
total AS totalNum
FROM
(
SELECT
CustomerId,
Phone,
Name,
FirstOrderTime,
LatestOrderTime,
CustomerLevel,
Call400Count,
OnlineOrderCount,
CityId,
CityName,
ROW_NUMBER () OVER (ORDER BY CustomerId DESC) rn,
COUNT (1) OVER () AS total
FROM
CustomerInfo WITH (NOLOCK)
WHERE
1 = 1
) AS t
WHERE
1 = 1
AND t.rn BETWEEN 1
AND 20