I am trying to make a leader board and use the following query:
SELECT d.*, 
       c.ranks 
FROM   (SELECT Max(correct_answer) AS correct_answer, 
               @rank := @rank + 1  Ranks 
        FROM   (SELECT Max(correct_answer) AS correct_answer 
                FROM   quiz_statuses 
                GROUP  BY user_id, 
                          level_no 
                ORDER  BY correct_answer DESC) t, 
               (SELECT @rank := 0) r) c 
       INNER JOIN quiz_statuses d 
               ON c.correct_answer = d.correct_answer 
My table looks like:
id,user_id,level_no,correct_answer
1    1        1       5
2    1        1      10
3    2        1      36
The expected result should be as follows:
id,user_id,level_no,correct_answer,ranks
3    2        1      36             1
2    1        1      10             2  
But my query does not give me the result I want.
 
    