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

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

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

# 找到 高难度SQL 试卷 得分平均值 大于80 并且是 7级 的 红名大佬
with A as (
select c.uid
from exam_record c
join user_info using(uid)
join examination_info using(exam_id)
where tag = 'SQL'
and difficulty = 'hard'
and level = 7
group by 1
having avg(score) > 80
)
# 统计他们的2021年试卷总完成次数和题目总练习次数,只保留2021年有试卷完成记录的用户
# 试卷总完成次数
,B as (
select uid,count(*)exam_cnt from exam_record
where uid in (select uid from A)
and year(start_time) = 2021
and submit_time is not null
group by 1
)
# 题目总练习次数
,C as (
select uid,count(*)question_cnt from practice_record
where uid in (select uid from B)
and year(submit_time) = 2021
and submit_time is not null
group by 1
)
# 连表 再空值转换
select uid,exam_cnt,ifnull(question_cnt,0)question_cnt
from (
select uid,exam_cnt,question_cnt
from B
left join C using(uid)
)a
order by exam_cnt,question_cnt desc

全部评论

相关推荐

09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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