← Back to CTEs
Question 48
Winter Sign-Ups Week by Week
Winter Sign-Ups Week by Week
Use a recursive CTE namedweeksto generate every Monday from2025-12-01to2026-01-12(seven dates one week apart, stepping withdate(…, '+7 days')). ThenLEFT JOINenrollmentsso each week counts the rows whoseenrolled_onfalls on or after that Monday and before the next one. Returnweek_startandsignups, sorted byweek_start; the three holiday weeks in the middle must show 0.
Expected result:
+------------+---------+ | week_start | signups | +------------+---------+ | 2025-12-01 | 15 | | 2025-12-08 | 13 | | 2025-12-15 | 0 | | 2025-12-22 | 0 | | 2025-12-29 | 0 | | 2026-01-05 | 4 | | 2026-01-12 | 2 | +------------+---------+ 7 rows
Hints4 available
Sign in to use hintsTopics:
CTEs
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.