题解 | #连续两次作答试卷的最大时间窗#
每份试卷每月作答数和截止当月的作答总数。
http://www.nowcoder.com/practice/5f1cbe74c682485aa73e4c2b30f04a62
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 month(start_time)) as cum_exam_cnt
from exam_record
group by exam_id, month(start_time)
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 month(start_time)) as cum_exam_cnt
from exam_record
group by exam_id, month(start_time)
离谱的是有时候能通过,有时候不能。