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

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

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

全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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