with t as( select in_datetime dt,course_id, 1 as type from attend_tb union all select out_datetime dt,course_id, -1 as type from attend_tb ) select course_id,course_name, max(num) as max_num from( select c.course_id,course_name, sum(type) over (partition by c.course_id order by dt,type desc) as num from course_tb c join t on c.course_id = t.course_id )b group by course_id,course_name order by course_id
瞬时最大问题