题目描述
https://www.nowcoder.com/practice/5f1cbe74c682485aa73e4c2b30f04a62
思路:每份试卷每个月的累计数量比较好求,总体的累计可以使用窗口函数进行sum,和普通的sum其实差不太多
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