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

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

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

# 先找到SQL类试卷得分平均值>80并且是7级的用户
with t1 as (
    select uid
    from exam_record
    where exam_id in (select exam_id from examination_info where tag = 'SQL')
    and score is not null
    and uid in (select uid from user_info where level = 7)
    group by uid
    having avg(score) > 80
),
t2 as (
# 统计他们在2021年试卷总完成次数和题目总练习数
    select uid, sum(if(score is null, 0, 1)) as exam_cnt
    from exam_record
    where uid in (select uid from t1)
    and year(start_time) = '2021'
    group by uid
)# 使用if处理没有练习试卷的情况
select t2.uid, t2.exam_cnt, if(a.question_cnt is null, 0, a.question_cnt) as question_id
from t2
left join (
    select uid, count(score) as question_cnt
    from practice_record
    where year(submit_time) = '2021'
    and uid in (select uid from t1)
    group by uid
) as a
on a.uid = t2.uid
order by t2.exam_cnt, question_cnt desc;

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 20:15
还能挽救吗?找同学帮忙看了一下 字节怎么能如此对我
牛客26396789...:你这是严重红线,被发现你自己永远进不去,你那个同学直接走人,你还敢宣扬
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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