SQL 87 ) 最差是第几名(一)
最差是第几名(一)
http://www.nowcoder.com/questionTerminal/ae5e8273e73b4413823b676081bd355c
用转置函数 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
SQL 文章被收录于专栏
SQL