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

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

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

select
    author,
    date_format (start_time, '%Y-%m') as month,
    round(
        sum(if (if_follow = 2, -1, if_follow)) / count(author),3
    ) fans_grouth_rate,
    sum(sum(if (if_follow = 2, -1, if_follow))) 
        over (partition by author order by date_format (start_time, '%Y-%m')) total_fans
-- 两层sum是因为第一个sum是针对每个月进行计算,第二个sum是为了每一个author在不同月份的累加
from tb_user_video_log t1 
    left join tb_video_info t2 on t1.video_id = t2.video_id
where year(start_time)=2021
group by
    author,
    month
order by
    author,
    total_fans

全部评论

相关推荐

06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
04-25 19:29
已编辑
宁波大学 测试开发
被普调的六边形战士很高大:你我美牛孩
点赞 评论 收藏
分享
06-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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