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