题解 | #作答试卷得分大于过80的人的用户等级分布#

作答试卷得分大于过80的人的用户等级分布

https://www.nowcoder.com/practice/5bc77e3a3c374ad6a92798f0ead4c744

#方法一: 嵌套子查询
select
    level,
    count(level) level_cnt
from (
    select
    t1.exam_id,
    level,
    tag
from (
    select
        exam_id,
        level
    from exam_record er
    left join user_info ui on er.uid= ui.uid
    where er.submit_time is not null
    and er.score > 80
)t1
left join examination_info ei on t1.exam_id = ei.exam_id
where tag = 'SQL'
)t2
group by level
order by level_cnt desc;

#方法二:
select
    ui.level,
    count(ui.uid) level_cnt
from user_info ui where uid in (
    select
        er.uid
    from examination_info ei 
    join exam_record er using(exam_id) 
    where ei.tag = 'SQL' and er.submit_time is not null  and er.score > 80
)group by level
order by level_cnt desc;

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 15:39
点赞 评论 收藏
分享
07-01 19:00
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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