题解 | #每篇文章同一时刻最大在看人数#
每篇文章同一时刻最大在看人数
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