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

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

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
全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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