要点:
1. nth_value() over (partition by)
2. 不能直接用timediff,因为和duration格式不同,然后用timestampdiff的话也不能用minute,因为最后一个用例很tricky(差值在秒位),所以得换成timestampdiff(second,........)
select distinct a.exam_id, a.duration, a.release_time from (select record.exam_id, nth_value(timestampdiff(second, record.start_time, record.submit_time),2) over (partition by record.exam_id order by timestampdiff(second, record.start_time, record.submit_time) desc) as slowest_2, nth_value(timestampdiff(second, record.start_time, record.submit_time),2) over (partition by record.exam_id order by timestampdiff(second, record.start_time, record.submit_time) asc) as fastest_2, info.duration, info.release_time from exam_record as record left join examination_info as info on record.exam_id = info.exam_id where record.score is not null) as a where (a.slowest_2 - a.fastest_2 ) > 0.5 * a.duration order by a.exam_id desc