题解 | #每篇文章同一时刻最大在看人数#
每篇文章同一时刻最大在看人数
https://www.nowcoder.com/practice/fe24c93008b84e9592b35faa15755e48
select artical_id, max(uv) as max_uv from ( select artical_id, sum(tag) over ( partition by artical_id order by dt, tag desc ) as uv from ( select artical_id, in_time as dt, 1 as tag from tb_user_log where artical_id <> 0 union all select artical_id, out_time as dt, -1 as tag from tb_user_log where artical_id <>0 ) as t1 ) as t2 group by artical_id order by max_uv desc;
对于t2子查询那里我有点不理解为啥要对tag desc,有没有大佬指点一下