题解 | #每月及截止当月的答题情况#

每月及截止当月的答题情况

http://www.nowcoder.com/practice/1ce93d5cec5c4243930fc5e8efaaca1e

# 每个人最早的活跃月份=当前月份,则是新增用户
# 新增用户数:sum(case when)
# 然后基于上面的东西做窗口函数求累积,单月最大新增用户数
# 按月份升序输出

select *,
max(month_add_uv)over(order by start_month) as max_month_add_uv,
sum(month_add_uv)over(order by start_month)as cum_sum_uv
from
(select start_month,
count(distinct uid)as mau,
count(distinct case when start_month=min_month then uid else null end) as month_add_uv
from
(select uid,date_format(start_time,'%Y%m') as start_month,
min(date_format(start_time,'%Y%m'))over(partition by uid) as min_month
from exam_record)a
group by start_month)b
order by start_month
全部评论

相关推荐

昨天 16:23
门头沟学院 Java
点赞 评论 收藏
分享
09-17 20:37
已编辑
长沙学院 Java
涂莱:学院本重心后移,金10银11,甚至金11银12,战线拉长一点,对于学院本来说秋招是个持久战,加油吧
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
用微笑面对困难:这里面最强的是驾驶证了,可以入职美团大厂,然后直接开启黄马褂人生
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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