Chodzi o to, aby zapytać „ile graczy ma ranking powyżej @this_user”:
select count(*) + 1 from
(
/* list of all users */
SELECT SUM( p.points ) AS sum_points
FROM user u
LEFT JOIN points p ON p.user_id = u.id
GROUP BY u.id
) x
/* just count the ones with higher sum_points */
where sum_points > (select sum(points) from points where user_id = @this_user)
Edytowane aby wynik był oparty na 1 zamiast na 0