with tiaojian as ( select artical_id,in_time as ptime from tb_user_log where artical_id<>0 union select artical_id,out_time as ptime from tb_user_log where artical_id<>0 ) select t.artical_id, max(cnt) as max_uv from( select t1.artical_id, count(tg.id) as cnt from tb_user_log tg inner join tiaojian t1 on tg.artical_id=t1.artical_id where t1.ptime between tg.in_time and tg.out_time group by t1.ptime,t1.artical_id ) as t group by t.artical_id order by max_uv desc