题解 | #满足条件的用户的试卷完成数和题目练习数#注意一定做了试卷,不一定做了题目
满足条件的用户的试卷完成数和题目练习数
http://www.nowcoder.com/practice/5c03f761b36046649ee71f05e1ceecbf
select t1.uid,t1.exam_cnt, coalesce(t2.question_cnt,0) as question_cnt from (select uid,count(1) as exam_cnt from exam_record where year(submit_time) = 2021 group by uid)t1 left join (select uid,count(1) as question_cnt from practice_record where year(submit_time) = 2021 group by uid)t2 on t1.uid = t2.uid where t1.uid in ( select t1.uid from user_info t1 join exam_record t2 on t1.uid = t2.uid join examination_info t3 on t2.exam_id = t3.exam_id where t3.tag = 'SQL' and t3.difficulty = 'hard' and t1.level = 7 group by t1.uid having avg(t2.score) > 80 ) order by exam_cnt,question_cnt desc