How does mysql get the rankings?

suppose the table stu is as follows

id user_id score
1  3        98
2  34       95
3  7        92
4  25       90
The

scores have been sorted in descending order. Now, according to the input user_id (7), the ranking should be 3. How to write the sql statement?

Mar.18,2021

your description of this problem is not clear enough. Have you checked the table you mentioned?
simply write:

in fact, it's just a virtual increment column when querying the table.


aren't user_id (7) and id (3) in the same column?


SELECT IF(
EXISTS(
    SELECT `score`
    FROM `stu`
    WHERE `user_id`=7
),
(
    SELECT COUNT(1)+1
    FROM `stu`
    WHERE `score` > (
        SELECT `score`
        FROM `stu`
        WHERE `user_id`=7
    )
), 
NULL);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eace7f-47ed4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eace7f-47ed4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?