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

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

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

1.row_number

select exam_id, duration, release_time from ( SELECT er.exam_id, uid, duration, release_time, TIMESTAMPDIFF(MINUTE, start_time, submit_time) as spend_time, ROW_NUMBER() over( partition by exam_id order by TIMESTAMPDIFF(MINUTE, start_time, submit_time) desc ) as rank1, ROW_NUMBER() over( partition by exam_id order by TIMESTAMPDIFF(MINUTE, start_time, submit_time) asc ) as rank2 from exam_record as er left join examination_info as ei on er.exam_id = ei.exam_id where submit_time is not null ) as a group by exam_id having sum( case when rank1 = 2 then spend_time when rank2 = 2 then - spend_time else 0 end ) * 2 >= duration order by exam_id desc

2.nth_value

SELECT distinct exam_id, duration, release_time FROM ( SELECT er.exam_id, uid, duration, release_time, TIMESTAMPDIFF(MINUTE, start_time, submit_time) as spend_time, nth_value(TIMESTAMPDIFF(MINUTE, start_time, submit_time), 2) over( PARTITION BY exam_id ORDER BY TIMESTAMPDIFF(MINUTE, start_time, submit_time) DESC ) as max2_time_took, nth_value(TIMESTAMPDIFF(MINUTE, start_time, submit_time), 2) over( PARTITION BY exam_id ORDER BY TIMESTAMPDIFF(MINUTE, start_time, submit_time) asc ) as min2_time_took FROM exam_record as er left JOIN examination_info ei on er.exam_id = ei.exam_id WHERE submit_time IS NOT NULL ) as a WHERE max2_time_took - min2_time_took >= duration / 2 ORDER BY exam_id DESC

全部评论

相关推荐

不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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