M
M
Maxim Grechushnikov2015-05-28 12:18:53
MySQL
Maxim Grechushnikov, 2015-05-28 12:18:53

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;

It turns out wrong . I
TWADwKe6Ad8.jpg
suspect that numbering and sorting occur in different realities ))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Mokhov, 2015-05-28
@maxyc_webber

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 question

Ask a Question

731 491 924 answers to any question