rank points player_id quiz_id
1 88 1 40
2 80 3 40
3 30 3 41
4 20 1 41
从以下查询获取此输出:
SELECT m.rank,
m.scorer AS points,
m.player_id
FROM
( SELECT d.player_id,
d.scorer, @rownum := @rownum + 1 AS rank
FROM
( SELECT t.player_id,
SUM(t.score) AS scorer
FROM answers t
JOIN PROFILE ON profile.player_id = t.player_id
JOIN quiz ON t.quiz_id = quiz.id
WHERE t.is_active = 1
AND quiz.contest_id = 1
AND profile.signin_source_id != 1
AND profile.is_active = 1
AND t.quiz_id IN (1,
2)
GROUP BY t.player_id
ORDER BY scorer DESC, t.created_utc ASC) d,
(SELECT @rownum := 0) r) m
WHERE m.scorer > 0
但是,我想要的输出是每个级别的等级。
rank points player_id quiz_id
1 88 1 40
2 80 3 40
1 30 3 41
2 20 1 41
我遵循这些原则:
如何在mysql中进行分组排名
https://blog.sqlauthority.com/2014/03/09/mysql-reset-row-number-for-each-group-partition-by-row-number/
但无法获得所需的输出。任何建议或帮助都将不胜感激。
3条答案
按热度按时间jogvjijk1#
试试这个
5vf7fwbs2#
尝试此查询,它更简单:
要将其合并到查询中,请尝试:
l5tcr1uw3#
最终得到了所需的结果,以查询结束,以便为级别获得适当的排名:
这将给出特定组的所有级别的整个结果集,如果要从特定组中获取特定级别的排名,请执行添加
感谢所有曾经参与的人!