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

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

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

select b.artical_id,
       max(b.cnt) as max_uv
from 
(select a.artical_id,
        sum(a.knub) over (partition by a.artical_id order by a.dt asc,a.knub desc) as cnt
from
(select artical_id,
        in_time as dt,
        1 as knub 
from tb_user_log
where artical_id != 0
union all 
select artical_id,
       out_time as dt,
       -1 as knub 
from tb_user_log
where artical_id != 0 ) a) b
group by b.artical_id
order by max_uv desc

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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