题解 | #每份试卷每月作答数和截止当月的作答总数。#
每份试卷每月作答数和截止当月的作答总数。
https://www.nowcoder.com/practice/5f1cbe74c682485aa73e4c2b30f04a62
# table exam_record # 每份试卷 每月作答数 # 每份试卷 截止当月作答数 (累加) sum order by # 根据示例可知只要有starttime 就算作答 with temp as ( select exam_id, date_format(start_time, '%Y%m') time1 from exam_record ) select e.*, sum(e.month_cnt) over (partition by e.exam_id order by e.start_month) cum_exam_cnt from( select exam_id, time1 start_month, count(*) month_cnt from temp group by exam_id, time1 ) e order by exam_id, start_month;