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

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

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

with t1 as(
    select artical_id, in_time as dt, 1 as diff
    from tb_user_log
    union all
    select artical_id, out_time as dt, -1 as diff
    from tb_user_log
)


select artical_id, max_uv
from
(select artical_id, max(counts) as max_uv
from
(select artical_id, sum(diff)over(partition by artical_id order by dt rows between unbounded preceding and current row) as counts
from
(select artical_id, dt, diff
from t1
order by dt) as t3) as t4
where artical_id !=0
group by artical_id) as t5
order by max_uv desc

全部评论

相关推荐

joecii:如果没有工资,那可能没有工资是这家公司最小的问题了
找实习记录
点赞 评论 收藏
分享
2025-12-11 14:24
门头沟学院 Java
牛客35720396...:不要用boss,全是骗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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