题解 | #满足条件的用户的试卷完成数和题目练习数#

满足条件的用户的试卷完成数和题目练习数

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

-- 请你找到高难度SQL试卷得分平均值大于80并且是7级的红名大佬,统计他们的2021年试卷总完成次数和题目总练习次数,只保留2021年有试卷完成记录的用户。结果按试卷完成数升序
with t as(
    select uid,exam_id,avg(score) as sc
    from exam_record 
    where year(start_time) = 2021
    group by uid,exam_id
),
a as (
    select t.uid,count(ifnull(t.exam_id,0)) as exam_cnt
from t
left join examination_info i
on t.exam_id = i.exam_id 
where t.uid in (
    select t.uid
    from t 
    left join examination_info f
    on t.exam_id = f.exam_id 
    where f.tag = 'SQL' and f.difficulty='hard' and t.sc > 80
) and t.uid in (
    select uid from user_info where level = 7
)
group by t.uid
)
select a.uid,exam_cnt,ifnull(r.question,0) as question_cnt
from a 
left join (select uid,count(question_id) as question
    from practice_record 
    where year(submit_time) =2021
    group by uid) r
on a.uid = r.uid
order by exam_cnt asc,question_cnt desc;

#SQL进阶#
全部评论

相关推荐

不愿透露姓名的神秘牛友
09-11 10:20
点赞 评论 收藏
分享
用微笑面对困难:这里面最强的是驾驶证了,可以入职美团大厂,然后直接开启黄马褂人生
点赞 评论 收藏
分享
08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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