复杂sql——分页查询同时查出数据总量

要求:每页显示5条数据,同事返回数据总量作为分页。
SELECT
*
FROM
(
SELECT
l.Address,
u.id,
l.Lat,
l.Log,
u.Account,
ui.Name,
u.State,
COUNT (1) OVER () AS [rowCount],//这是总数量
row_number () OVER (ORDER BY [Time] DESC) AS row_number//这是排序
FROM
Users u,
UserInfo ui,
Location l
WHERE
u.id = l.Userid
AND u.id = ui.UsersId
AND ui.name LIKE ‘%王%’
AND l.[time] = (
SELECT
MAX ([Time])
FROM
Location
WHERE
UserId = l.Userid
)
AND l.Comid = 24
) t
WHERE
t.row_number > 0
AND t.row_number <= 5

你可能感兴趣的:(复杂sql——分页查询同时查出数据总量)