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

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

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

/*题意:试卷得分按分界点[90,75,60]分为优良中差四个得分等级,未完成过试卷的用户无需输出
题解: 1.首先,将存在试卷考试记录的所有得分和用户进行等级划分,后续需要计算得分等级占比,所以需要exam_id分散开
2. 各个等级用户的得分登记占比,相当于为统计出各个等级用户的优良中差次数占比总数
*/
select b.level
,b.score_grade
,round((b.num/sum(b.num)over(partition by b.level)),3) as rate
from (
    select a.level,a.score_grade
    ,count(a.score_grade) as num
    from
    (
    select e.uid,e.exam_id,u.level,e.score,
    case when e.score <60 then '差'
        when e.score <75 and e.score>= 60 then '中'
        when e.score < 90 and e.score>=75 then '良'
        when e.score >= 90 then "优"
        end as score_grade
    from exam_record e 
    left join user_info u
    on e.uid = u.uid 
    where e.score is not null
        )a
group by a.level, a.score_grade
)b
group by b.level,b.score_grade
order by b.level desc,rate desc 


数据库刷题题解 文章被收录于专栏

数据分析数据库题目练习题解

全部评论

相关推荐

lingo12:1.最好加个业务项目,大部分面试官工作以后会更偏重业务 2.实习部分描述一般般,可能hr看到会觉得你产出不够不给你过简历 3.蓝桥杯这些大部分人都有的,不如不写,反而减分项。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
02-12 10:05
小米集团 算法工程师 28.0k*15.0
泡沫灬一触即破:楼上那个看来是看人拿高薪,自己又不如意搁这泄愤呢是吧,看你过往评论很难不怀疑你的精神状态
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务