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

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

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

全部评论

相关推荐

会不会进去就面临裁员啊....
MellowWW:我朋友签的美区销售岗,这才是天崩开局
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务