题解 | #每个创作者每月的涨粉率及截止当前的总粉丝量#

每个创作者每月的涨粉率及截止当前的总粉丝量

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

WITH
    t1 AS (
        SELECT
            video_id,
            date_format(start_time,'%Y-%m') end_month,
            YEAR (end_time) AS year_time,
            CASE
                WHEN if_follow = 1 THEN 1
                WHEN if_follow = 2 THEN -1
                else 0
            END as if_follow
        FROM
            tb_user_video_log
        WHERE YEAR (end_time) = 2021
    )
SELECT
    vin.author,
    uv.end_month,
    round(Sum(uv.if_follow)/count(1),3) AS fans_growth_rate,
    sum(SUM(uv.if_follow)) OVER (
        PARTITION BY
            vin.author
        ORDER BY
            
            uv.end_month
    ) AS total_fans
FROM
    t1 uv
    LEFT JOIN tb_video_info vin ON uv.video_id = vin.video_id
WHERE
    uv.year_time = 2021
GROUP BY
    vin.author,
    uv.end_month
order by 
    vin.author,
    total_fans

全部评论

相关推荐

点赞 评论 收藏
分享
10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
10-11 17:30
湖南大学 C++
我已成为0offer的糕手:羡慕
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务