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

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

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

with slow_2nd as (
    select exam_id, slow_use
    from (
        select exam_id, timestampdiff(second, start_time, submit_time) slow_use,
            row_number()over(partition by exam_id order by timestampdiff(second, start_time, submit_time) desc) slow_rank
        from exam_record
        where submit_time is not null
    ) a
    where slow_rank = 2
),
    fast_2nd as (
    select exam_id, fast_use
    from (
        select exam_id, timestampdiff(second, start_time, submit_time) fast_use,
            row_number()over(partition by exam_id order by timestampdiff(second, start_time, submit_time)) fast_rank
        from exam_record
        where submit_time is not null
        ) b 
    where fast_rank = 2
)    
    select exam_id, duration, release_time
    from examination_info
    left join slow_2nd using (exam_id)
    left join fast_2nd using (exam_id)
    where (slow_use - fast_use) * 2 > duration * 60
    order by exam_id desc
注意:比较时间的时候,一定要注意精确度,应该按题目中给出的最小精确度来进行比较(如果没有特别说明的话)
本题应该精确到秒
全部评论

相关推荐

每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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