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

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

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

SELECT
    author
    ,m_onth AS month
    ,ROUND(follows/ct,3) AS fans_growth_rate
    ,SUM(follows)OVER(PARTITION BY author ORDER BY m_onth) AS total_fans
FROM
(
    SELECT
        t2.author
        ,LEFT(t1.start_time,7) AS m_onth
        ,SUM(CASE if_follow WHEN 1 THEN 1 WHEN 0 THEN 0 WHEN 2 THEN -1 END) AS follows
        ,COUNT(t1.video_id) as ct  
    FROM tb_user_video_log AS t1 LEFT JOIN tb_video_info AS t2
    ON t1.video_id=t2.video_id
    GROUP BY
        t2.author
        ,m_onth
) AS t1
WHERE LEFT(m_onth,4)=2021
ORDER BY author,total_fans


全部评论

相关推荐

给我一个offer吧求求啦:轮到大佬给公司发感谢信了,想想就爽
点赞 评论 收藏
分享
头像
昨天 11:19
中南大学 Java
哇为,遥遥领先
求你了offer啊啊啊啊啊啊啊啊啊啊:我的评价是华为比亚迪是每个混子的温柔乡
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务