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

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

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

思路:分别统计符合要求uid的2021年试卷总完成次数和题目总练习次数,然后连表

t和t1筛选符合要求uid;

t2储存符合要求uid的2021年试卷总完成次数

t3储存符合要求uid的2021年题目总练习次数

连表t2 left join t3,连接过程question_cnt可能产生none(t2两条记录,t3只有一条),用if把none换成0。exam_cnt没必要

with t as (
select uid,avg(score) as avg_sc
from exam_record t left join examination_info t1 on t.exam_id=t1.exam_id
where tag='SQL' and difficulty = 'hard'
group by uid),
t1 as (
select t.uid as uid
from t left join user_info t1 on t.uid=t1.uid
where level = 7 and avg_sc > 80),
t2 as(
select uid,count(score) as exam_cnt
from exam_record
where uid in (select uid from t1) and year(start_time) = 2021
group by uid),
t3 as (
select uid,count(score) as question_cnt
from practice_record
where uid in (select uid from t1) and year(submit_time) = 2021
group by uid)

select t2.uid as uid,
if(exam_cnt is null,0,exam_cnt) as exam_cnt,
if(question_cnt is null,0,question_cnt) as question_cnt
from t2 left join t3 on t2.uid=t3.uid
where exam_cnt<>0
order by exam_cnt,question_cnt desc

全部评论

相关推荐

兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
07-01 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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