Answer the question
In order to leave comments, you need to log in
MySQL: How to calculate a place in a rating? Where is the mistake?
SET @rank=0;
SELECT @rank:[email protected]+1 AS rank, p.user_id, SUM(ch.integer) as sum
FROM profile p
LEFT JOIN chronometry ch ON ch.user_id = p.user_id
GROUP BY p.user_id
ORDER BY sum DESC;
Answer the question
In order to leave comments, you need to log in
SET @rank=0;
SELECT @rank:[email protected]+1 AS rank, s.*
FROM (
SELECT p.user_id, SUM(ch.integer) as sum
FROM profile p
LEFT JOIN chronometry ch ON ch.user_id = p.user_id
GROUP BY p.user_id
ORDER BY sum DESC
) s
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question