select
uid,
max(datediff(next_s_t,start_time))+1 as days_window,
round((max(datediff(next_s_t,start_time))+1)*count(exam_id)/(datediff(max(start_time),min(start_time))+1),2) as avg_exam_cnt
from (
select uid,exam_id,
start_time,
lead(start_time) over (partition by uid order by start_time) as next_s_t
from exam_record where YEAR(start_time)=2021
)t1
group by uid having count(distinct date_format(start_time,'%m%d'))>1
order by days_window desc,avg_exam_cnt desc