Skip to content

Instantly share code, notes, and snippets.

@glafarge
Created February 27, 2014 16:40
Show Gist options
  • Save glafarge/9253838 to your computer and use it in GitHub Desktop.
Save glafarge/9253838 to your computer and use it in GitHub Desktop.
Find rank of an user based on score
SELECT id, username, score,
FIND_IN_SET(
score, (SELECT GROUP_CONCAT(DISTINCT score ORDER BY score DESC) FROM score)
) as rank
FROM scores;
id username score rank
1 wallace 95 2
2 gromit 97 1
3 shaun 85 4
4 mcgraw 92 3
5 preston 92 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment