题解 | #各用户等级的不同得分表现占比#

各用户等级的不同得分表现占比

http://www.nowcoder.com/practice/ebff819fd38c46db8a42dfe43ca7b33a

# 每个成绩都有等级:case when[90,75,60]分为优良中差
# 根据每个人分组,sum(case when)


select level,score_grade,
round(count(score)/max(total_cnt),3) as ratio
from
(
    select ui.uid,level,score,
    (case when score between 90 and 100 then '优' when score between 75 and 89 then '良' when score between 60 and 74 then '中' else '差' end) as score_grade,
    count(score)over(partition by level) as total_cnt
    from exam_record er join user_info ui using(uid)
    where score is not null
)a
group by level,score_grade
order by level desc,ratio desc

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
希望奇迹发生的布莱克...:真的是 现在卷实习就是没苦硬吃
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务