select artical_id, max(cnt_uv) as max_uv from ( ( select artical_id, sum(uv) over ( partition by artical_id order by time, uv desc ) as cnt_uv from ( select artical_id, in_time as time, 1 as uv from tb_user_log union all select artical_id, out_time as time, -1 as uv from tb_user_log ) a where artical_id !=0 ) ) b group by artical_id order by max_uv desc