select exam_id, count(distinct uid) as uv, round(sum(score)/count(uid),1) as avg_score from exam_record join examination_info using(exam_id) join user_info using(uid) where level > 5 and tag = 'SQL' and submit_time is not null and DATE_FORMAT(submit_time, "%Y%m%d") = DATE_FORMAT(release_time, "%Y%m%d") group by exam_id order by uv desc, avg_score