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

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

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

with tb as (
    select author, date_format(start_time, "%Y-%m") as month,
    sum(case when if_follow = 2 then -1 else if_follow end) / count(*) as fans_growth_rate, 
    sum(case when if_follow = 2 then -1 else if_follow end) as fans_this_month
    from tb_user_video_log uvl
    left outer join tb_video_info vi
    on uvl.video_id = vi.video_id
    where year(start_time) = 2021
    group by author, month
    order by author, month
)
select author, month, round(fans_growth_rate, 3) as fans_growth_rate, sum(fans_this_month) over(partition by author order by month) as total_fans
from tb
order by author, total_fans;

这次被卡在累加一列了,窗口函数可以干这个。

以及我只能在CTE里加年份条件,加在外面 (year(month) = 2021) 跑不了。

全部评论

相关推荐

06-18 08:36
湖南大学 Java
运营你豪哥:没啥拷打的 1.增加量化结果,现在有点缺效果数据 2.突出复杂性,现在的项目描述有点像功能清单,强调一下技术难点和解决方案。
不给转正的实习,你还去吗
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:17
听说过付费实习,没想到这么贵啊我去,要不我给你个腰子吧
哈哈哈,你是老六:这种公司一定要注意啊,不要随便签合同,只要签了后面钱可能回不来,而且你通过法律途径也弄不回
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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