题解 | #第二快/慢用时之差大于试卷时长一半的试卷#

第二快/慢用时之差大于试卷时长一半的试卷

https://www.nowcoder.com/practice/b1e2864271c14b63b0df9fc08b559166

select distinct exam_id
        ,duration
        ,release_time
from(
    select er.exam_id
    /*作答时间timestampdiff(second,start_time,submit_time)第二快*/
            ,nth_value(timestampdiff(second,start_time,submit_time),2) over(partition by exam_id order by timestampdiff(second,start_time,submit_time) desc) AS fast_2 
            ,nth_value(timestampdiff(second,start_time,submit_time),2) over(partition by exam_id order by timestampdiff(second,start_time,submit_time) asc) AS last_2
            ,duration
            ,release_time
    from exam_record er
    inner join examination_info ei on er.exam_id = ei.exam_id
)t1
where fast_2 - last_2 > duration*30
order by exam_id desc

1、timestampdiff(second, start_time, submit_time)计算出作答时间,单位秒

2、nth_value(timestampdiff(secon, start_time, submit_time),2) over(partion by exam_id .....desc/asc)取出每类试卷exam_id作答时间第二快和第二慢的值,是一个开窗函数。每一行答题记录都添加last_2和fast_2,形成表t1

3、从t1中取出满足条件的exam_id

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-13 19:30
化身华黑 今天询问对接人审批情况,结果被告知没HC了 云计算 
苦闷的柠檬精allin实习:主管面结束后hr每周保温一次,结果前几天和我说没hc了,我也化身华黑子了
点赞 评论 收藏
分享
05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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