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

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

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

with t as (select uid,artical_id,in_time as dt, 1 as flag from tb_user_log where artical_id!=0 union all select uid,artical_id,out_time as dt, -1 as flag from tb_user_log where artical_id!=0)

select w.artical_id ,max(w.cc) z from

(select artical_id, sum(flag) over(partition by artical_id order by dt,flag desc) as cc from t) w group by w.artical_id order by z desc

全部评论

相关推荐

11-01 20:03
已编辑
门头沟学院 算法工程师
Amazarashi66:这种也是幸存者偏差了,拿不到这个价的才是大多数
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务