Answer the question
In order to leave comments, you need to log in
How to determine where in the ranking a user is?
There is a list of users, each has a percentage of progress.
I need the user to see where he is among all the students.
I've been trying to find similar information for a long time but I can't.
Answer the question
In order to leave comments, you need to log in
window function. ROW_NUMBER . Or RANK . The implementation is determined by the specific DBMS.
What DB? Mysql has variables and you can do something like this:
SELECT name,
percent,
@curRank := @curRank + 1 AS rank
FROM students s, (SELECT @curRank := 0) r
ORDER BY percent desc;
SELECT name,
percent,
dense_rank() over (order by percent desc) rating
FROM students
ORDER BY 1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question