题解 | #连续两次作答试卷的最大时间窗#
select uid,windowDays, format(examTimes*1.0/startToEndDays * windowDays,2) as avg_exam_cnt from ( select uid, max(datediff(end,start)) + 1 as windowDays, datediff(max(start),min(start))+1 as startToEndDays, count(1) as examTimes from ( select uid, start_time as start, lead(start_time,1,start_time) over(partition by uid order by start_time) as end from exam_record where year(start_time)=2021 ) a group by a.uid ) t1 where t1.startToEndDays > 1 order by windowDays desc,avg_exam_cnt desc