id | username | score | rank |
---|---|---|---|
1 | wallace | 95 | 2 |
2 | gromit | 97 | 1 |
3 | shaun | 85 | 4 |
4 | mcgraw | 92 | 3 |
5 | preston | 92 | 3 |
Created
February 27, 2014 16:40
-
-
Save glafarge/9253838 to your computer and use it in GitHub Desktop.
Find rank of an user based on score
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT id, username, score, | |
FIND_IN_SET( | |
score, (SELECT GROUP_CONCAT(DISTINCT score ORDER BY score DESC) FROM score) | |
) as rank | |
FROM scores; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment