题解 | #牛客直播各科目同时在线人数#
牛客直播各科目同时在线人数
https://www.nowcoder.com/practice/d69677e41f9a4bf3b3ed7a42573e9490
请大家帮我看看哪里可以优化的~ with a as (select user_id,course_id,in_datetime dt,1 as uv from attend_tb union all select user_id,course_id,out_datetime dt,-1 as uv from attend_tb) select course_id,course_name,max(num) from (select b.course_id,b.num,c.course_name from (select course_id,sum(uv) over (partition by course_id order by dt) num from a )b left join course_tb c on b.course_id=c.course_id)d group by course_id,course_name order by course_id