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

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

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

全部评论

相关推荐

hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
object3:开始给部分🌸孝子上人生第一课了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务