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

select
    a.uid uid,
    exam_cnt,
    if (question_cnt is null, 0, question_cnt) question_cnt
from
    (
        select
            ui.uid uid,
            count(distinct er.exam_id) exam_cnt
        from
            test.user_info ui
            left join test.exam_record er on ui.uid = er.uid
            left join test.examination_info ei on er.exam_id = ei.exam_id
        where
            ui.uid in (
                select
                    ui.uid
                from
                    test.user_info ui
                    left join test.exam_record er on ui.uid = er.uid
                    left join test.examination_info ei on er.exam_id = ei.exam_id
                where
                    tag = 'SQL'
                    and difficulty = 'hard'
                    and level = 7
                    and year (start_time) = 2021
                group by
                    ui.uid
                having
                    avg(score) > 80
            )
            and year (start_time) = 2021
        group by
            ui.uid
    ) a
    left join (
        select
            uid,
            count(question_id) question_cnt
        from
            test.practice_record
        where
            uid in (
                select
                    ui.uid
                from
                    test.user_info ui
                    left join test.exam_record er on ui.uid = er.uid
                    left join test.examination_info ei on er.exam_id = ei.exam_id
                where
                    tag = 'SQL'
                    and difficulty = 'hard'
                    and level = 7
                    and year (start_time) = 2021
                group by
                    ui.uid
                having
                    avg(score) > 80
            )
            and year (submit_time) = 2021
        group by
            uid
    ) b on a.uid = b.uid
order by
    exam_cnt asc,
    question_cnt desc

全部评论

相关推荐

05-05 21:45
已编辑
广州大学 Java
点赞 评论 收藏
分享
05-12 17:00
门头沟学院 Java
king122:你的项目描述至少要分点呀,要实习的话,你的描述可以使用什么技术,实现了什么难点,达成了哪些数字指标,这个数字指标尽量是真实的,这样面试应该会多很多,就这样自己包装一下,包装不好可以找我,我有几个大厂最近做过的实习项目也可以包装一下
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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