题解 | #每个创作者每月的涨粉率及截止当前的总粉丝量 用了临时表,可读性好

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

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

with t as (
  select author,date_format(start_time,'%Y-%m') month
  ,sum(case when if_follow=1 then 1 when if_follow=2 then -1 else 0 end ) total_fans --每月粉丝量
  ,round(sum(case when if_follow=1 then 1 when  if_follow=2 then -1 else 0 end )/count(start_time),3) fans_growth_rate --每月涨粉率
  from tb_user_video_log tvl
  inner join tb_video_info tvi
  on tvl.video_id=tvi.video_id
  where year(start_time)='2021'
  group by author,date_format(start_time,'%Y-%m')
)
select author,month
,fans_growth_rate
,sum(total_fans)over(partition by author order by month ) total_fans_cum -- 截至当月累计粉丝量
from t
order by author,total_fans_cum
全部评论

相关推荐

09-19 14:17
门头沟学院 Java
点赞 评论 收藏
分享
今晚做笔试的还有机会约面吗?有听说后面做笔试的会被认为来华为的意愿度不是很高.....
ggrr:不会,华为笔试都要排队的。不是说想写就能发的。有的人投递晚了几天就排在后面写了。
投递华为技术有限公司等公司10个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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