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

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

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

select author,imonth,
        round(sum(
            case 
            when if_follow=1 then 1
            when if_follow=2 then -1
            else 0 end
        )/count(*),3) as fans_growth_rate,
        sum(sum(
            case 
            when if_follow=1 then 1
            when if_follow=2 then -1
            else 0 end
        ) ) over(partition by author order by imonth) as total_fans
from
    (select video_id,
            date_format(start_time,'%Y-%m') as imonth,
            if_follow
    from tb_user_video_log
    where year(start_time) = 2021) as a
    left join tb_video_info b using(video_id)
group by author,imonth
order by author,total_fans;

全部评论

相关推荐

不愿透露姓名的神秘牛友
2025-11-20 12:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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