题解 | 牛客直播各科目同时在线人数
牛客直播各科目同时在线人数
https://www.nowcoder.com/practice/d69677e41f9a4bf3b3ed7a42573e9490
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.course_name, max(b.zaixian) max_num from b left join course_tb c on b.course_id=c.course_id group by 1,2