Answer the question
In order to leave comments, you need to log in
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
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question