题解 | #满足条件的用户的试卷完成数和题目练习数#
满足条件的用户的试卷完成数和题目练习数
https://www.nowcoder.com/practice/5c03f761b36046649ee71f05e1ceecbf
with data_f_use 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 group by uid having avg(score) > 80 ), 2021_exam_complete as ( select uid, count(exam_id) as exam_cnt from exam_record where submit_time is not null and year(submit_time) = 2021 and uid in (select uid from data_f_use) group by uid ), 2021_practice_time as ( select uid, count(uid) as question_cnt from practice_record where year(submit_time) = 2021 and uid in (select uid from data_f_use) group by uid ) select uid, exam_cnt, ifnull(question_cnt,0) from 2021_exam_complete left join 2021_practice_time using (uid) order by exam_cnt, question_cnt descCommon Table Expression 真香