题解 | #每份试卷每月作答数和截止当月的作答总数。#
每份试卷每月作答数和截止当月的作答总数。
http://www.nowcoder.com/practice/5f1cbe74c682485aa73e4c2b30f04a62
问题分析
1、每份试卷每月作答数——GROUP BY + COUNT() 2、每份试卷截止当月的作答总数——SUM()OVER()
答案参考
SELECT
exam_id,date_format(start_time,'%Y%m')start_month
,count(start_time)mouth_cnt
,sum(count(start_time))over(partition by exam_id order by date_format(start_time,'%Y%m'))cum_exam_cnt
FROM
exam_record
GROUP BY
exam_id,date_format(start_time,'%Y%m');