SQL163面试真题
统计每篇文章同一时刻最大在看人数
select artical_id, max(uv)max_uv from
(
select artical_id, sum(tag)over(partition by artical_id order by time, tag DESC)uv from
(
select artical_id, in_time as time, 1 as tag from tb_user_log union all
select artical_id, out_time as time, -1 as tag from tb_user_log
)a
)b
where b.artical_id != 0
group by b.artical_id
order by max_uv DESC