思路:做两个登入登出表,分别是登入时间 和 1, 登出时间 -1 用union all合并(因为可能有人是同时登入) , 状态字段用status表示然后用窗口 求窗口大小为( 上无限到当前位置的, status的sum() ),即可求出, 某时刻最大在线人数with t1 as(select artical_id,in_time time , 1 as statusfrom tb_user_logwhere artical_id!=0union allselect artical_id,out_time time , -1 as statusfrom tb_user_log where artical_id!=0), t2 as(select artical_id, sum(status)over(partition by artical_id order by time rows between unbounded preceding and current row ) cntfrom t1)select artical_id,max(cnt) max_uvfrom t2group by artical_idorder by max_uv desc;#解题#