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

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

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

全部评论

相关推荐

qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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