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

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

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

with data_f_use as (
    select uid
    from exam_record
    left join examination_info using (exam_id)
    left join user_info using (uid)
    where difficulty = 'hard' and tag = 'SQL' and level = 7
    group by uid
    having avg(score) > 80
), 2021_exam_complete as (
    select uid, count(exam_id) as exam_cnt
    from exam_record
    where submit_time is not null
    and year(submit_time) = 2021
    and uid in (select uid from data_f_use)
    group by uid
), 2021_practice_time as (
    select uid, count(uid) as question_cnt
    from practice_record
    where year(submit_time) = 2021
    and uid in (select uid from data_f_use)
    group by uid
)
    select uid, exam_cnt, ifnull(question_cnt,0)
    from 2021_exam_complete
    left join 2021_practice_time using (uid)
    order by exam_cnt, question_cnt desc
Common Table Expression 真香
全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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