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

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

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

我先把各个作者各个月份的播放量(num),本月粉丝增加量(fans)存储为res:

with res as (
    select
        author,
        date_format(end_time,'%Y-%m') as 'month',
        count(1) as 'num',
        sum(if(if_follow=2,-1,if_follow)) as 'fans'
    from tb_user_video_log as A
    left join tb_video_info as B
    using(video_id)
    group by author,month
)

根据res再计算当前粉丝和涨粉率,以及对年份进行筛选和排序

select 
    author,
    month,
    round(fans/num,3) as 'fans_growth_rate',
    (select sum(fans) from res as t where t.month <= A.month and t.author = A.author) as 'total_fans'
from res as A
where month like '2021%'
order by author,total_fans
全部评论

相关推荐

不愿透露姓名的神秘牛友
11-24 20:55
阿里国际 Java工程师 2.7k*16.0
程序员猪皮:没有超过3k的,不太好选。春招再看看
点赞 评论 收藏
分享
10-30 22:18
已编辑
毛坦厂中学 C++
点赞 评论 收藏
分享
10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务