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

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

https://www.nowcoder.com/practice/d69677e41f9a4bf3b3ed7a42573e9490

select course_id, course_name, max(so) as max_num
from (
    select course_id,sum(uv) over(partition by course_id order by dt) as so
    from (
        select course_id, user_id, in_datetime as dt, 1 as uv
        from attend_tb
        union 
        select course_id, user_id, out_datetime as dt, -1 as uv
        from attend_tb
    ) a
) b join course_tb using(course_id)
group by course_id, course_name
order by course_id

全部评论

相关推荐

牛客868257804号:九个中铁八个中建
点赞 评论 收藏
分享
喜欢吃蛋糕仰泳鲈鱼是我的神:字节可以找个hr 给你挂了,再放池子捞
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务