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

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

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

with temp as(
  select
    user_id,
    attend_tb.course_id,
    course_name,
    in_datetime as dt,
    1 as flag
  from
    attend_tb
    left join course_tb on attend_tb.course_id = course_tb.course_id
  union all
  select
    user_id,
    attend_tb.course_id,
    course_name,
    out_datetime as dt,
    -1 as flag
  from
    attend_tb
    left join course_tb on attend_tb.course_id = course_tb.course_id
)
select
course_id,course_name,max(num)
from
  (
    select
      course_id,
      course_name,
      sum(flag) over(
        partition by course_id
        order by
          dt
      ) as num
    from
      temp
  ) t
  group by course_id,course_name
  order by course_id
全部评论

相关推荐

09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
未知的命运:大佬这都找不到我还找啥啊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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