题解 | 牛客直播各科目同时在线人数

牛客直播各科目同时在线人数

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

全部评论

相关推荐

点赞 评论 收藏
分享
皮格吉:不,有的厂子面试无手撕,可以试试。都是一边学一边面。哪有真正准备好的时候,别放弃
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务