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

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

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

SELECT artical_id, max(cnt) as max_uv
FROM
(
    SELECT artical_id, uid, tms, status,
    SUM(status) over(partition BY artical_id ORDER BY tms ASC,status desc) as cnt
    FROM(
         SELECT artical_id, uid, in_time as tms,1 as status
         FROM tb_user_log
         UNION ALL
         SELECT artical_id, uid, out_time as tms,-1 as status
         FROM tb_user_log
    ) as tmp
)as tmp
WHERE artical_id !=0
GROUP BY artical_id
ORDER BY max_uv desc

全部评论

相关推荐

Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务