select a.author,a.month,a.ra, sum(fans) over(partition by a.author order by a.month) mf from (select author,date_format(end_time,'%Y-%m') month, round(sum(case when if_follow=2 then -1 else if_follow end)/count(start_time),3) as ra ,sum(case when if_follow=2 then -1 else if_follow end) fans from tb_user_video_log t1 join tb_video_info t2 on t1.video_id=t2.video_id where year(end_time)='2021' group by author,month ) a order by a.author,mf;