解法1:直接求和

SELECT c.grade,(
SELECT SUM(d.number)
FROM class_grade AS d
WHERE d.grade<=c.grade
) AS t_rank
FROM class_grade AS c
ORDER BY c.grade

解法2:窗口函数

SELECT c.grade,SUM(c.number) OVER(ORDER BY c.grade) AS t_rank
FROM class_grade AS c