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

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

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

with t as (
select author, tb_video_info.video_id, date_format(start_time,"%Y-%m") as month, case
when if_follow = 2 then -1
else if_follow
end as if_follow
from tb_video_info
left join tb_user_video_log
on tb_user_video_log.video_id = tb_video_info.video_id
where year(start_time)=2021
)

select author, month, 
# 1. 2021年里每个创作者每月的涨粉率
round(sum(if_follow)/count(if_follow),3) as fans_growth_rate,
# 2. 2021年里每个创作者截止当月的总粉丝量
sum(sum(if_follow)) over(partition by author order by month) as total_fans
from t
group by author, month
order by author, total_fans

每个创作者截止当月的总粉丝量:按时间累加每个创作者每月的总粉丝数

即 ( sum(每个创作者每月的总粉丝数 ) over(partition by 创作者 order by month))

每个创作者每月的总粉丝数 = sum(if_follow) group by author, month

每个创作者截止当月的总粉丝量 = sum(每个创作者每月的总粉丝数) over(partition by author order by month)

= sum(sum(if_follow)) over(partition by author order by month) group by author, month

全部评论

相关推荐

smile丶snow:感觉可以加一些ai相关的内容吧。现在面试很少能逃掉这些问题。羡慕里面感觉缺少一个项目背景。比如第二个项目后台管理系统…你为什么要做这个后台管理系统呢?是为了解决什么问题。比如你管理一个商品列表的增加减少。需要一个背景吧。哦或者说你第一个电子书那个是c端的,你肯定需要一个管理系统吧,那就是第二个后台管理系统,但这两个难道不应该是一个项目吗?可以稍微包装一下,最起码让人看着不是玩具项目。个人观点。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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