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

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

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

select 
    artical_id,
    max(sum_uv) as max_uv
from(    
    select 
        artical_id,
        tm,
        sum(uv) over (partition by artical_id order by tm,uv desc) as sum_uv
    from(
        select 
            artical_id,
            in_time as tm,
            1 as uv
        from 
            tb_user_log
        where artical_id != 0
        UNION ALL
        select 
            artical_id,
            out_time as tm,
            -1 as uv
        from 
            tb_user_log
        where artical_id != 0) as a) as b
group by artical_id
order by max_uv desc

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务