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

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

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

#首次登录
with a as(
select uid,date_format(min(start_time),'%Y%m') as first_month
from exam_record
group by uid
)

select date_format(start_time,'%Y%m') as start_month,
count(distinct er.uid) as mau,
count(distinct case when a.first_month = date_format(start_time,'%Y%m') then er.uid else null end ) as month_add_uv,
max(count(distinct case when a.first_month = date_format(start_time,'%Y%m') then er.uid else null end ) ) over (order by date_format(start_time,'%Y%m') ) as max_month_add_uv,
sum(count(distinct case when a.first_month = date_format(start_time,'%Y%m') then er.uid else null end ) ) over (order by date_format(start_time,'%Y%m')) as cum_sum_uv

from exam_record er
left join a on a.uid=er.uid

group by date_format(start_time,'%Y%m')

中等难度

全部评论

相关推荐

04-18 00:32
已编辑
中南大学 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务