题解 | #第二快/慢用时之差大于试卷时长一半的试卷#比较时间差用秒
第二快/慢用时之差大于试卷时长一半的试卷
http://www.nowcoder.com/practice/b1e2864271c14b63b0df9fc08b559166
select exam_id,duration,release_time from ( select exam_id,duration,release_time,times, row_number()over(partition by exam_id order by times) as fast_rn, row_number()over(partition by exam_id order by times desc) as slow_rn from ( select t1.exam_id,timestampdiff(second,start_time,submit_time) as times, t1.duration,t1.release_time from examination_info t1 join exam_record t2 on t1.exam_id = t2.exam_id where submit_time is not null )t3 ) t group by exam_id,duration,release_time having sum(if(slow_rn=2,times,0)) - sum(if(fast_rn=2,times,0)) > duration * 30 order by exam_id desc