题解 | #第二快/慢用时之差大于试卷时长一半的试卷#
第二快/慢用时之差大于试卷时长一半的试卷
https://www.nowcoder.com/practice/b1e2864271c14b63b0df9fc08b559166
// 临时表:目的是将答题时长做一个排序 with d as ( select exam_id, time, ROW_NUMBER() over (partition by exam_id order by time desc) as asc_ranking, # 答题时长时间排序,求出第二快 ROW_NUMBER() over (partition by exam_id order by time asc) as desc_ranking, # 求出第二慢 duration, release_time from ( SELECT a.exam_id, TIMESTAMPDIFF( MINUTE, start_time, submit_time ) as time, // 关键一步:通过timestampdiff函数求时长 duration, release_time FROM exam_record a LEFT JOIN examination_info b ON a.exam_id = b.exam_id ) c) select a.exam_id, a.duration, a.release_time from( select * from d where asc_ranking = 2) a left join (select * from d where desc_ranking = 2) b on a.exam_id = b.exam_id where (a.time-b.time)>(a.duration/2) order by a.exam_id desc