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

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

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

# 涨粉率 = (加粉量 - 掉粉量) / 播放量。结果按创作者ID、总粉丝量升序排序。
# 2021 每月的涨粉, 截至当月的总粉丝量
# sum(case uv.if_follow when 1 then 1 when 2 then -1 end) over (partition by vi.author order by month(uv.start_time)) as fans_change
# 以人为窗口,按照月份排序,
# 构造字段,粉丝变化数
# 每个作者每月的涨粉, 截至当月的总粉丝数
# 每人每月  partition by vi.author order by date_format(uv.start_time, "%Y%m") 

select  distinct
    vi.author
    , date_format(uv.start_time, "%Y-%m") as `month`
    , round(avg(case uv.if_follow when 1 then 1 when 2 then -1 else 0 end) over (partition by vi.author, month(uv.start_time)), 3) as fans_growth_rate
    , sum(case uv.if_follow when 1 then 1 when 2 then -1 end) over (partition by vi.author order by month(uv.start_time)) as total_fans
from tb_video_info as vi 
left join tb_user_video_log as uv on vi.video_id = uv.video_id
where year(uv.start_time) = 2021
order by vi.author, total_fans

全部评论

相关推荐

09-25 00:00
已编辑
电子科技大学 Java
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的 const flattern = (obj) => { const res = {}; const dfs = (curr, path) => { if(typeof curr === 'object' && curr !== null) { const isArray = Array.isArray(curr); for(let key in curr) { const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key; dfs(curr[key], newPath); } } else { res[path] = curr } } dfs(obj); return res; }
查看3道真题和解析
点赞 评论 收藏
分享
09-29 16:59
已编辑
门头沟学院 Java
牛客96609213...:疯狂背刺,之前还明确设置截止日期,还有笔试,现在一帮人卡在复筛,他反而一边开启扩招,还给扩招的免笔试,真服了,你好歹先把复筛中的给处理了再说
投递大疆等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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