整体挺简单的,需要关注的是timestampdiff这个function,别的像是datediff和timediff都是第一个输入时间减去第二个输入时间,但是它是第二个输入时间减去第一个输入时间。

select distinct uid, "activity1" as act from exam_record
where score >= 85

union all 

select distinct uid, "activity2" as act
from examination_info join exam_record using(exam_id)
where difficulty = "hard" and score > 80 and 
      timestampdiff(second, start_time, submit_time)<duration * 60 / 2
order by uid, act