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

连续两次作答试卷的最大时间窗

https://www.nowcoder.com/practice/9dcc0eebb8394e79ada1d4d4e979d73c

select b.uid as uid, b.diff as days_window, round(b.diff*b.avg_cnt,2) as avg_exam_cnt
from
(
    select a.uid as uid, 
    max(datediff(a.start_time,a.new_time)+1) as diff, 
    count(*)/(1+datediff(max(a.start_time),min(a.start_time))) as avg_cnt
    from 
        ( 
            select uid, exam_id,start_time,submit_time,score,
            lag(start_time,1)over(partition by uid order by start_time) as new_time
            from exam_record
            where year(start_time)=2021
        )as a
    group by uid
    having count(distinct(date_format(start_time,'%Y%m%d'))) >=2) as b
order by days_window desc, avg_exam_cnt desc

全部评论
首先对原表格进行了变形,增加一列前一天作答日期,相减之后按uid分组得出登录间隔分布,第二层子查询在此基础上筛选最大登录间隔,同时计算平均每天刷题频率,最后回归本题,将最大分布与平均刷题频率相乘得出最终答案
点赞 回复 分享
发布于 06-19 14:46 河南

相关推荐

06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
06-20 16:12
门头沟学院 Java
rakkaus:助学金,,,这个就不用写吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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