题解 | #每篇文章同一时刻最大在看人数#

每篇文章同一时刻最大在看人数

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

#统计<每篇文章><同一时刻>《最大》在看人数,如果同一时刻有进入也有离开时,先记录用户数增加再记录减少,结果按最大人数降序。
with t as 
(select t1.artical_id, sum(t1.uv) over (partition by t1.artical_id order by t1.time, t1.uv desc )as online_uv 
          from 
           (select artical_id, in_time as time ,1 as uv from tb_user_log
           union all
           select artical_id, out_time as time ,-1 as uv from tb_user_log )as t1
          where artical_id<>0 
           )

select t.artical_id, max(online_uv) as max_uv
from t
group by artical_id
order by max_uv desc;

全部评论

相关推荐

竟然收到了测评听说是双机位
投递拼多多集团-PDD等公司10个岗位
点赞 评论 收藏
分享
07-31 14:10
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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