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

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

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

全部评论

相关推荐

04-03 13:58
上海大学 Java
3月15号笔的,1-AC\2-90%\3-60%\4-AC泡了半个月今天早上起来看不通过,到底是谁在面试网易啊
只会CV的高级程序员:你a不过 你是985也找你面试 不太懂现在用人单位到底怎么想的 建议不用笔试 直接每个985都招就行了 挂科的退学的
投递网易等公司8个岗位 >
点赞 评论 收藏
分享
1个小白:可以考虑投一下字节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务