select exam_id,count(distinct t1.uid) as uv, round(avg(score),1) as avg_score from exam_record t1 join user_info t2 on t1.uid = t2.uid and t2.level > 5 where (exam_id,date_format(start_time,'%Y%m%d')) in ( select exam_id,date_format(release_time,'%Y%m%d') as re_day from examination_info where tag = 'SQL' ) group by exam_id order by uv desc,avg_score