题解 | #每篇文章同一时刻最大在看人数#

每篇文章同一时刻最大在看人数

https://www.nowcoder.com/practice/fe24c93008b84e9592b35faa15755e48

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

全部评论

相关推荐

尊嘟假嘟点击就送:加v细说,问题很大
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务