with a as(select user_id, course_id, in_datetime as time, 1 as uv from attend_tb union all select user_id, course_id, out_datetime as time, -1 as uv from attend_tb), b as(select *, sum(uv)over(partition by course_id order by time) as zaixian from a order by course_id, time) select b.course_id, c.cou...