该题用到的几个知识点如下:
① 求年月:date_format(start_time,'%Y-%m')
② 求年份:year(start_time)='2021'
③每月涨粉量:sum(case when if_follow=1 then 1 when if_follow=2 then -1 else 0 end)
④总播放量:count(if_follow)
⑤截至到当前的粉丝量,这里有个很重要的知识点
    a)每月涨粉量sum(case when if_follow=1 then 1 when if_follow=2 then -1 else 0 end) as fans
    b)然后用到聚类窗口函数sum(fans) over(partition by author order by date_format(start_time,'%Y-%m'))
    这里是在聚合函数的基础上再叠加聚类窗口函数,非常NICE!
完整SQL如下:
select author,date_format(start_time,'%Y-%m') as month,
             round(sum(case when if_follow=1 then 1 when if_follow=2 then -1 else 0 end)/count(if_follow),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 date_format(start_time,'%Y-%m')) as total_fans
from tb_user_video_log
join tb_video_info
using(video_id)
where year(start_time)='2021'
group by author,month
order by author,total_fans