题目描述:SQL查询,如果一个学生知道了自己综合成绩以后,最差是排第几名? 结果按照grade升序排序。

题目:
grade number
A 2
D 1
C 2
B 2

sum(number) over(order by grade) 窗口函数
按照grade升序依次累加number
A 2
B 2+2
C 2+2+2
D 2+2+2+1

代码:

select grade, sum(number) over(order by grade) as t_rank
from class_grade