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

全部评论

相关推荐

贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
10 1 评论
分享
牛客网
牛客企业服务