I have this table:
id leaderboard_id player_id score
1 1 3 5001
2 1 2 501
3 1 4 490
4 2 3 1001
5 2 2 110
I want to get the player_id = 3 rank on both leaderboards (leaderboard_id = 1 and 2).
I tried many options with no success, they give me rank 1 in leaderboard 1, rank 2 in leaderboard 2, when they both should be rank 1.
Last code that gave me those results is:
SELECT * FROM ( SELECT s.*, @rank := @rank + 1 rank FROM ( SELECT leaderboard_id, player_id, score FROM leaderboards t GROUP BY leaderboard_id ) s, (SELECT @rank := 0) init ORDER BY score DESC ) r WHERE player_id = 3
... with this result:
If anyone can point to a solution, it would be very appreciated.
Thank you