Sql group ranking

the structure of the table is as follows:

    id      id    
    student_id course_id score
    1          1         60
    1          2         50
    1          3         70
    2          1         20
    2          2         40
    ...
    ...

without considering that the total score is the same, how to query the number of people who are higher than the total score of student_id=10, that is, their own ranking?

Apr.04,2021

try this, okay?

-sharp table_name
SELECT COUNT(student_id) FROM table_name GROUP BY student_id HAVING SUM(score) > (SELECT SUM(score) FROM table_name WHERE student_id = 10); 

score:'''select score from table where student_id=10'''
:'''select count(1) as cnt from table where score>'{0}' '''.format(score)
Menu