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

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

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

全部评论

相关推荐

把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
挣K存W养DOG:他真的很中意你,为什么不回他
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务