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

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

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

with t1 as (select author,
                   substr(end_time, 1, 7)            as mon,
                   count(if(if_follow = 1, 1, null)) as addfensi,
                   count(if(if_follow = 2, 1, null)) as subfensi,
                   count(1)                          as tol
            from tb_user_video_log t1
                     join tb_video_info t2
                          on t1.video_id = t2.video_id
            where substr(end_time, 1, 4) = 2021
            group by substr(end_time, 1, 7), author)
select author,
       mon,
       round((addfensi - subfensi) / tol, 3)  as fans_growth_rate,
       sum(addfensi - subfensi)
           over (partition by author order by mon,addfensi,subfensi  ) as total_fans
from t1 order by author,total_fans;

全部评论

相关推荐

10-10 01:10
已编辑
深圳大学 测试开发
面了100年面试不知...:六月到九月,四个项目一个实习,是魔丸吗
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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