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

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

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

错了4次。每一次都是错在最后的结果。

逻辑不难,思路是先找出目标用户。再连两次表。

前三次错误:最后order by 的时候写错列。以及没考虑到两份题目均要在2021年的情况。 第四次错误:没考虑到可能有未完成。 最后通过结果:

#高难度、SQL、平均分大于80,用户等级为7,2021年有试卷完成记录的用户。
#上述用户 2021年,试卷总完成次数、题目总练习数。
#结果按试卷完成数升序,按题目练习数降序。
with a as (
select u.uid from user_info u 
left join  exam_record e1 on u.uid=e1.uid
left join  examination_info e2 on e1.exam_id=e2.exam_id
where tag = 'sql' and difficulty ='hard' and level = 7
group by u.uid having avg(score) > 80 )

select a.uid,
count(distinct if(e2.id is not null ,e2.id,null)) exam_cnt,
count(distinct if( p.id is not null ,p.id,null)) question_cnt from
a left join exam_record e2 on a.uid=e2.uid
left join practice_record p on a.uid=p.uid and p.submit_time like '2021%'
where e2.submit_time like '2021%'
group by a.uid
having exam_cnt > 0
order by exam_cnt,question_cnt desc
全部评论

相关推荐

06-18 08:36
湖南大学 Java
运营你豪哥:没啥拷打的 1.增加量化结果,现在有点缺效果数据 2.突出复杂性,现在的项目描述有点像功能清单,强调一下技术难点和解决方案。
不给转正的实习,你还去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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