I'm aware there are already many questions alike however none of those answers helped me achieve row rankings in a table.
I have a table set up as so:
+----------------------------------+---------------+--------+
| HEX(UUID) | Username | Rating |
+----------------------------------+---------------+--------+
| 0000F659C5854C9DB8BE8984FEC8CFD9 | Aidan8or_ | 1600 |
| 00022E3531F44C36AE058B3CF063C02F | rob160502 | 1600 |
| 000399B665D14979B3C0AF309112625F | HauntedCorpse | 1536 |
| 0003BAC2C0764C0C9FE20C4A3C701D7E | Glitchx0R | 1234 |
| 000597056E564BF587DAA1D31E51E29F | jkz101022 | 455 |
+----------------------------------+---------------+--------+
What I would like to do here is select a single row with a ranking appended to it (1, 2, 3, 10, 100, …). If you haven't already guessed it, the rating is an ELO Rating therefore many scores are tied and I need to accommodate for that when creating leaderboards.
I've taken a look at this: Get the rank of a user in a score table and it had some really good answers but I just couldn't get any of them working correctly.
I've tried all those solutions and got close with this:
SELECT HEX(UUID) as UUID, Username, Rating, FIND_IN_SET( Rating, (
SELECT GROUP_CONCAT( Rating
ORDER BY Rating DESC )
FROM table_name )
) AS rank
FROM table_name
WHERE Username = 'jkz101022'
however returns the ranking as 0.
Best Answer
You must evaluate everybody's rank and select the Username last
If you want the original row, then do this
UPDATE 2014-08-25 16:57 EDT
I Fixed My Code
I got this outout
UPDATE 2014-08-25 17:15 EDT
I tried it with
rob160502
and got this:UPDATE 2014-08-25 17:38 EDT
I even tried
HauntedCorpse
and got this:Give it a Try !!!
CAVEAT : Please note that the results come from your actual data in SQLFiddle. I simply loaded the data into a test database and ran my code against it.