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

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

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

select er.uid,count(distinct er.exam_id) as exam_cnt,
count(distinct pr.submit_time) as question_cnt
#计数提交时间,就避免了表连接时的重复性
from exam_record as er
left join examination_info as ei using(exam_id)
left join user_info as ui 
on er.uid=ui.uid and year(er.submit_time)='2021'
left join practice_record as pr 
on er.uid=pr.uid and year(pr.submit_time)='2021'
#在连接表时限制2021
where ui.level=7
and er.uid in 
(select exam_record.uid from exam_record left join examination_info using(exam_id)
 where tag='SQL' and difficulty='hard'
 group by exam_record.uid
 having avg(score)>80
)
#该语句是为了将SQL平均分数超过80的uid筛选出来
group by er.uid
order by exam_cnt asc,question_cnt desc

全部评论

相关推荐

11-27 12:36
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务