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

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

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

/*
核心信息:高难度,SQL,平均值大于80,7级;【2021年】 试卷总完成次数和题目总练习次数
1、先找出符合条件的uid,并将其作为子表,可以用with创建临时表,这样代码逻辑比较清晰
2、分别根据uid在exam_record和practice_record进行查询
3、将两个表的查询结果根据uid进行合并
4、对合并表进行总的查询
*/

with tmp as (
select uid
from exam_record left join examination_info using(exam_id) left join user_info using(uid)
where difficulty='hard'
    and tag='SQL'
    and level=7
    and year(submit_time)=2021
group by uid
having avg(score)>80
)

select uid, exam_cnt, if(question_cnt is null, 0, question_cnt)
from
(select uid, count(submit_time) as exam_cnt
from exam_record
where uid in (select uid from tmp) and year(submit_time)=2021
group by uid) t1

left join 

(select uid, count(submit_time) as question_cnt
from practice_record
where uid in (select uid from tmp) and year(submit_time)=2021
group by uid) t2 using(uid)

order by exam_cnt asc, question_cnt desc

全部评论

相关推荐

06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 16:15
我应届生,去年10月份开始在这家公司实习,到今年10月份正好一年想(实习+试用期),在想要不要提前9月份就离职,这样好找工作些,但又差一个月满一年,又怕10月份国庆回来离职,容易错过了下半年的金九银十,到年底容易gap到年后
小破站_程序员YT:说这家公司不好吧,你干了快一年 说这家公司好吧,你刚毕业就想跑路说你不懂行情吧,你怕错过金九银十说 你懂行情吧,校招阶段在实习,毕业社招想换工作 哥们,我该怎么劝你留下来呢
应届生,你找到工作了吗
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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