带分页的MySQL排名
我有一个SQL查询,看起来像:带分页的MySQL排名,mysql,sql,ranking,Mysql,Sql,Ranking,我有一个SQL查询,看起来像: SELECT member_id, Count(*) AS '# of Rounds' FROM score,cup_point WHERE session_id =? AND tour_id =? AND cup_point_id = `cup_point`.id GROUP BY member_id ORDER BY Sum(points) DESC LIMIT 50 offset 0 如何在查询中包含排名,以便:
SELECT member_id, Count(*) AS '# of Rounds'
FROM score,cup_point
WHERE session_id =?
AND tour_id =?
AND cup_point_id = `cup_point`.id
GROUP BY member_id
ORDER BY Sum(points) DESC
LIMIT 50 offset 0
如何在查询中包含排名,以便:
总和(点数)
,因此最高分数的排名为1,以此类推member\u id
)
?谢谢。可能有子查询和运行计数器
SET @x = 0;
SELECT member_id,NumRounds AS '# of Rounds',@x:=(@x+1) Rank FROM
(
SELECT member_id, Count(*) AS NumRounds
FROM score,cup_point
WHERE session_id =?
AND tour_id =?
AND cup_point_id = `cup_point`.id
GROUP BY member_id
ORDER BY Sum(points) DESC
LIMIT 50 offset 0
) A;
试试看