The following query will give you a new column UserRank
, which specify the user rank:
SELECT
UserID,
Score,
(@rownum := @rownum + 1) UserRank
FROM table_score, (SELECT @rownum := 0) t
ORDER BY Score DESC;
SQL Fiddle Demo
This will give you something like:
| USERID | SCORE | USERRANK |
-----------------------------
| 4 | 100 | 1 |
| 10 | 70 | 2 |
| 2 | 55 | 3 |
| 1234 | 50 | 4 |
| 1 | 36 | 5 |
| 20 | 33 | 6 |
| 8 | 25 | 7 |
Then you can put this query inside a subquery and filter with a userId
to get that user rank. Something like:
SELECT
t.UserRank
FROM
(
SELECT *, (@rownum := @rownum + 1) UserRank
FROM table_score, (SELECT @rownum := 0) t
ORDER BY Score DESC
) t
WHERE userID = '1234';
SQL Fiddle Demo