select exam_id, date_format(start_time,"%Y%m") as start_month, count(start_time) as month_cnt, sum(count(start_time)) over (partition by exam_id order by date_format(start_time,"%Y%m")) as cum_exam_cnt from exam_record group by exam_id,start_month
# 考核知识点:
# 聚合窗口函数的使用,sum() over (patition by 字段 order by 字段 )
# patition by 是分组依据 order by 是排序依据 ,sum(count(start_time))是总和统计start_time的次数和,其中容易出错的地方是over()里面的排序依据,不可以直接写 order by start_month 会报错,必须写成date_format(start_time,"%Y%m")
注:以上内容仅为个人笔记,方便自己回头查看,若有题友提出建议,欢迎,望大家多多交流,互相学习