题解 | #每月及截止当月的答题情况#
每月及截止当月的答题情况
https://www.nowcoder.com/practice/1ce93d5cec5c4243930fc5e8efaaca1e
select start_month,count(distinct uid) as mau, sum(new_day) as month_add_uv, max(sum(new_day)) over(order by start_month) as max_month_add_uv, sum(sum(new_day)) over(order by start_month) as cum_sum_uv from( select *,date_format(start_time,'%Y%m') as start_month, if(start_time = min(start_time)over(partition by uid),1,0) as new_day from exam_record) as t1 group by start_month
先统计一下每个月新出现的人数new_day,然后使用窗口函数进行统计,