Mysql get ranking question

get the current ranking according to the conditions

uid user id
score score
game_time Game time
create_time creation time

get the ranking of current users based on score, game time, and record insertion time

ranking method: the score is from small to big on Mini Game, and the recording time is from small to big

.

Oct.19,2021

I'm sorry I didn't see the title clearly.
my stupid idea is to use two sql.
suppose the score is 10000, the game time is 10s, the creation time, 2018-11-1
first use the first sql to calculate how many numbers are greater than 10000. Get count1
SELECT count (id) FROM table WHERE score '10000seconds;
then use a sql to calculate a total of score=10001,game_time < 10s. Get count2.
SELECT count (id) FROM table WHERE score > '10000' AND game_time <' 10slots;

the ranking result is count1+count2;. If you want to use a sentence, you can use a subquery. There is no train of thought at present.


if the amount of data is small, just write sql according to your idea.


select , (select count () from table as a where a.score > b.score) + 1 as rank from table as b where b.uid=581

query score is greater than the number of users to query ranking, rank is ranking

Menu