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

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

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

select
    artical_id,
    max(uv) as max_uv
from
    (
        select
            artical_id,
            sum(tag) over (
                partition by
                    artical_id
                order by
                    dt, tag desc
            ) as uv
        from
            (
                select
                    artical_id,
                    in_time as dt,
                    1 as tag
                from
                    tb_user_log
                where
                    artical_id <> 0
                union all
                select
                    artical_id,
                    out_time as dt,
                    -1 as tag
                from
                    tb_user_log
                where
                    artical_id <>0
            ) as t1
    ) as t2
group by
    artical_id
order by
    max_uv desc;

对于t2子查询那里我有点不理解为啥要对tag desc,有没有大佬指点一下

全部评论

相关推荐

大佬们考的怎么样?看样子不能只刷acm编程题了,机器学习题也要刷下。😭
牛客561236133号:绷不住了,皮什么玩意来着
投递美团等公司10个岗位 >
点赞 评论 收藏
分享
后端彭于晏:你无敌了
点赞 评论 收藏
分享
想问问各位大佬,同时拿到了美团和虾皮的前端实习,该怎么选呀?
寒小枫:实习选美团 秋招同薪资选虾皮
投递美团等公司10个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务