SELECT t1.exam_id, t1.duration, t1.release_time from( select t.exam_id, t.duration, t.release_time, sum(case when t.m=2 then diff when t.d=2 then -diff else 0 end) as p from ( select e2.exam_id, e2.duration, e2.release_time, timestampdiff(MINUTE,e1.start_time,e1.submit_time) as diff, row_number()over(partition by e1.exam_id order by TIMESTAMPDIFF(minute,e1.start_time,e1.submit_time) desc ) as m , row_number()over(partition by e1.exam_id order by TIMESTAMPDIFF(minute,e1.start_time,e1.submit_time) asc ) as d from exam_record e1 right join examination_info e2 on e1.exam_id=e2.exam_id WHERE e1.submit_time is not null ) as t group by t.exam_id ) as t1 WHERE t1.p>=t1.duration/2 order by t1.exam_id desc 思路 1. 先找到,最第二个做题速度及倒数第二个 所用,先用timestampdiff求出时间差,通过时间差,按照EXAM_ID,进行排序,找出。 然后,要排除submit_time is null 必须是非空。 2. 第二部 做判断根据题目要求,每个exam_id第二时间差+倒数第二慢时间差,大于所在的duration一半,就能求出来了