题解 | #每篇文章同一时刻最大在看人数#
每篇文章同一时刻最大在看人数
https://www.nowcoder.com/practice/fe24c93008b84e9592b35faa15755e48
select artical_id, max(cnt) as max_uv from ( select artical_id, dt, SUM(diff) OVER ( PARTITION BY artical_id ORDER BY dt,diff desc ) as cnt from ( select artical_id, in_time as dt, 1 as diff from tb_user_log where artical_id != 0 union all select artical_id, out_time as dt, -1 as diff from tb_user_log where artical_id != 0 ) t1 ) t2 group by artical_id order by max_uv desc; # 这道题是看了题解才写出来的,但是这个思路学到了。