SQL163 每篇文章同一时刻最大在看人数
SELECT artical_id, MAX(p_num) AS max_uv FROM( SELECT artical_id, mark, SUM(mark) OVER(PARTITION BY artical_id ORDER BY time , mark DESC) AS p_num FROM( SELECT artical_id, in_time AS time, 1 AS mark FROM tb_user_log AS u1 WHERE artical_id <> '0' UNION ALL SELECT artical_id, out_time AS time, '-1 AS mark FROM tb_user_log AS u2 WHERE artical_id <> '0') AS a) AS b GROUP BY artical_id ORDER BY max_uv DESC