select level,score_grade,round(num2/num1,3) as ratio
from (
			select level,score_grade,
						 count(score_grade) as num2
			from (
						select level,
									 case when score<60 then '差'
												when score>=60 and score<75 then '中'
												when score>=75 and score<90 then '良'
												when score>=90 then '优'
												end as score_grade
						from exam_record
						left join user_info using(uid)
						where submit_time is not null
						) as t
			group by level,score_grade
			) as t1
left join (
		select level,count(submit_time) as num1
		from exam_record
		left join user_info using(uid)
		group by level) as t2 using(level)
order by level desc,ratio desc