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