R
R
ruboss2016-10-11 11:17:59
MySQL
ruboss, 2016-10-11 11:17:59

How to sample the user's position in the rating?

Hello!
There is a query that fetches the Nth number of users by rating:

SELECT d.login, t.count
FROM `".Constant::TOPS_TABLE."` t, `".Constant::USERS_TABLE."` u, `".Constant::DATA_TABLE."` d
WHERE u.id = t.user_id AND u.id = d.user_id AND t.tdate = :tdate
ORDER BY t.count DESC
LIMIT :limit

How can I find out the place in the rating of a particular user?
SELECT d.login, t.count, ROW_NUMBER() OVER(ORDER BY t.count DESC) AS place
FROM `".Constant::TOPS_TABLE."` t, `".Constant::USERS_TABLE."` u, `".Constant::DATA_TABLE."` d
WHERE u.id = t.user_id AND u.id = d.user_id AND t.tdate = :tdate AND u.id = :user_id

Googling found ROW_NUMBER () gives a syntax error, who knows what the problem is? Or maybe there are other ways to solve this problem?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-10-11
@ruboss

ROW_NUMBER is about M S SQL
for mysql, you need to pervert: mysql get row number - this is for the general top
in order to calculate a specific user: mysql get user rank
In short: we count the number of users BEFORE the desired user, subtract / add 1, get the user's position like this way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question