select 
b.exam_id,
count(distinct b.uid) uv,
format(sum(b.score) /count( b.uid),1)  avg_score
from  
examination_info a,
exam_record b,
user_info c
where a.exam_id=b.exam_id
and a.tag='SQL'
and b.submit_time is not null
and date_format(b.submit_time,'%y%m%d')=date_format(a.release_time,'%y%m%d')
and b.uid=c.uid
and c.level>5
group by b.exam_id
order by uv desc,avg_score asc