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

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

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


/*
select  A.author,
        A.month,
        round((A.addFanscnt-A.subtrFanscnt)/A.videoCnt,3) fans_growth_rate,
        sum(addFansMonth) over(partition by A.author order by A.month) total_fans 
    from (
   select tvi.author,
          date_format(tvl.start_time,'%Y-%m') month ,
          count(if(tvl.if_follow=1,1,null)) addFanscnt,
          count(if(tvl.if_follow=2,1,null)) subtrFanscnt,
          count(tvl.start_time) videoCnt,
          count(if(tvl.if_follow=1,1,null))-count(if(tvl.if_follow=2,1,null)) addFansMonth 
     from tb_user_video_log tvl join tb_video_info tvi using(video_id) 
    where year(tvl.start_time) = 2021 
    group by tvi.author,date_format(tvl.start_time,'%Y-%m')  
    ) A 
    order by author,total_fans ; 
    */

     select tvi.author,
          date_format(tvl.start_time,'%Y-%m') month ,
          round((count(if(tvl.if_follow=1,1,null))-count(if(tvl.if_follow=2,1,null)))/count(tvl.start_time),3) fans_growth_rate, 
          sum(count(if(tvl.if_follow=1,1,null))-count(if(tvl.if_follow=2,1,null))) 
          over(partition by tvi.author order by date_format(tvl.start_time,'%Y-%m')) total_fans 
     from tb_user_video_log tvl join tb_video_info tvi using(video_id) 
    where year(tvl.start_time) = 2021 
    group by tvi.author,date_format(tvl.start_time,'%Y-%m') 
    order by tvi.author,total_fans ;

全部评论

相关推荐

09-18 20:41
阿里巴巴_后端
要个offer怎么这...:哈哈哈哈哈哈,我也拿了0x10000000个offer,秋招温啦啦啦,好开心
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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