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

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

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

select
  t1.course_id,
  t2.course_name,
  max(t1.num) max_num
from
  (
    select
      course_id,
      sum(tag) over(
        partition by course_id
        order by
          time
      ) num
    from
      (
        select
          course_id,
          in_datetime time,
          1 tag
        from
          attend_tb
        union all
        select
          course_id,
          out_datetime time,
          -1 tag
        from
          attend_tb
      ) t
  ) t1
  left join course_tb t2 on t1.course_id = t2.course_id
group by
  t1.course_id,
  t2.course_name
order by
  t1.course_id
#sql#
全部评论

相关推荐

10-24 12:13
投递快手等公司10个岗位
点赞 评论 收藏
分享
克蕾儿_:我不用点进来都知道评论区什么样子
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务