用转置函数 case when 解决
select grade , case grade when 'A' then (select sum(number) from class_grade where grade <= 'A') when 'B' then (select sum(number)from class_grade where grade <= 'B') when 'C' then (select sum(number)from class_grade where grade <= 'C') when 'D' then (select sum(number)from class_grade where grade <= 'D') else (select sum(number) from class_grade) end from class_grade order by grade
用窗口函数sum()over()解决
select grade, sum(number)over(order by grade asc)t_rank from class_grade order by grade