题解 | #连续两次作答试卷的最大时间窗#


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


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务