select uid,max(timestampdiff(day,t,next_t)+1) as maxt,
round(
    max(timestampdiff(day,t,next_t)+1)    *
    sum(cnt)/ (timestampdiff(day,min(t),max(t))+1)   ,2) as avg_exam_cnt
from(select uid,t,lead(t,1,0) over(partition by uid order by t) as next_t,cnt
     from(
     select uid,date(start_time) t,count(exam_id) as cnt
     from exam_record where start_time like '2021%' group by 1,2 order by 1,2)a
    )b
group by 1 having count(t)>1
order by 2 desc,3 desc