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

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

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,有没有大佬指点一下

全部评论

相关推荐

自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务