SQL189大厂面试真题类似SQL49题

统计直播各科目同时在线人数

核心代码如下:

select course_id, times, sum(tag)over(partition by course_id order by times)num from

(

        select course_id, in_datetime as times, 1 as tag from attend_tb union all

        select course_id, out_datetime as times, -1 as tag from attend_tb

        order by course_id, times

)a

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务