What is a good design for a ranking system

I have a table USERthat has fields userIdand point. At runtime, I want to know what is ranking a specific user base at their point. What is the best way to do this:
1: query all users on a list. Sort the list base by point and perform a binary search to find the rating of this user. That sounds good. 2: Is it possible to complete these tasks by creating database queries?

I expect 2000-5000 users.

+3
source share
1 answer
SET @rownum := 0;

SELECT rank, userId, point 
FROM (
       SELECT @rownum := @rownum + 1 AS rank, userId, point
       FROM user ORDER BY point DESC
     ) 
as result WHERE userId = xxxxxxxx
+5
source

Source: https://habr.com/ru/post/1779245/


All Articles