rank points player_id quiz_id
1 88 1 40
2 80 3 40
3 30 3 41
4 20 1 41
Getting this output from the following query:
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
However, the output I want is rank for each level separated out.
rank points player_id quiz_id
1 88 1 40
2 80 3 40
1 30 3 41
2 20 1 41
I followed these :
How to perform grouped ranking in MySQL
But can't get the desired output. Any suggestion or help is appreciated.