SQL interview question: Cumulative Sum Over Time
Cumulative Student Enrollment Growth
The growth team wants to visualize total cumulative enrollments over time.
Calculate the running total of new student enrollments by month.
Return enrollment_month (YYYY-MM format), new_students (count per month), and cumulative_total (running sum). Use SUM() OVER.
Skills: window function SUM() OVER with running total
Tables
students 25 rows
- student_id integer PK
- name text
- email text
- grade_level integer
- gpa real
- enrollment_date text
| student_id | name | grade_level | gpa | enrollment_date | |
|---|---|---|---|---|---|
| 1 | Alice Johnson | [email protected] | 12 | 3.9 | 2024-09-01 |
| 2 | Bob Smith | [email protected] | 12 | 3.7 | 2024-09-01 |
| 3 | Carol Williams | [email protected] | 12 | 3.8 | 2024-09-01 |