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

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

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

with a as
(
    select author, date_format(start_time,'%Y-%m') as month,
        sum(
            case when if_follow=1 then 1 
            when if_follow=2 then -1
            else 0
            end
            ) fans_num,
        count(*) as play_amount
    from tb_video_info v
    join tb_user_video_log u
    on u.video_id = v.video_id
    where year(start_time)=2021
    group by author,month
)

select author, month,
    round(fans_num/play_amount,3) as fans_rate,
    sum(fans_num) over(partition by author order by month) as total_fans
from a
order by author, total_fans

全部评论

相关推荐

06-26 15:35
武汉大学 运营
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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