I want to rank the total stats of a group of users and assign a rank variable to them. I used this thread for the Rank variable.
This is my Query atm:
SELECT @rank := @rank + 1 AS rank
, SUM(stats.points) AS x
FROM
( SELECT @rank := 0 ) r
, groups
LEFT
JOIN user_group
ON groups.id = user_groups.clan
LEFT
JOIN stats
ON user_groups.user = stats.id
GROUP
BY groups.id
ORDER
BY x DESC
RANK | points
--------------
47 | 3400
1 | 2500
75 | 1200
As you can see the Sorting by Points works fine, but the Rank variable seems to just pick random values. Can anyone find a way to assign the rank correctly?