一种更少嵌套的sql实现方法

select uid,start_month,total_cnt,complete_cnt
from (
		select uid,
					 dense_rank() over(partition by uid order by date_format(start_time,'%Y%m') desc) as recent_month,
					 date_format(start_time,'%Y%m') as start_month,
					 count(start_time) as total_cnt,
					 count(submit_time) as complete_cnt
		from exam_record
		left join user_info using(uid)
		where level=6 or level=7
		group by uid,start_month
		) as t2
where recent_month<=3 and uid in (
		select uid
		from (
			select uid,row_number() over(order by incomplete_rate desc) as ranking
			from (
				select uid,
							 count(if(submit_time is null,1,null))/count(start_time) as incomplete_rate
				from exam_record
				left join examination_info using(exam_id)
				where tag='SQL'
				group by uid
				) as t
		) as t1
		where ranking<=ceiling((select count(distinct uid) from exam_record
													 left join examination_info using(exam_id)
													 where tag='SQL')/2)
																	)
order by uid,start_month