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

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

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

with s1 as(select uid
,date_format(start_time,'%Y%m') start_month
,row_number()over(partition by uid order by date_format(start_time,'%Y%m')) ranking 
from exam_record) 
select start_month,mau,month_add_uv
,max(month_add_uv)over(rows between unbounded preceding and current row) max_month_add_uv 
,sum(month_add_uv)over(rows between unbounded preceding and current row) cum_sum_uv
from (
select t1.start_month,t1.mau,coalesce(t2.mau,0) month_add_uv from
(
select start_month,count(distinct uid) mau 
from s1
group by start_month
) t1
left join 
(
select start_month,count(distinct uid) mau from s1
where ranking = 1
group by start_month
) t2
on t1.start_month = t2.start_month)  t3;

全部评论

相关推荐

04-28 11:34
西北大学 运营
牛客4396号:不好意思,这个照片猛一看像丁真
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务