Weekly ticket change

mediumSQL~20 min · 4 tests · helpdesk

The support lead reviews ticket volume every Monday. For each week they want the count, last week’s count, and the difference.

A week starts on Monday. A ticket belongs to the week containing its opened_at, so a ticket opened Sunday at 23:59 belongs to the week that started six days earlier. Report the week as the Monday’s date (2025-01-01 is a Wednesday, so the first week is 2024-12-30).

Return one row per week that has at least one ticket:

column type meaning
week_start date the Monday that starts the week
tickets integer tickets opened that week
prev_tickets integer tickets from the previous row; NULL for the first week
change integer tickets - prev_tickets; NULL for the first week

The shipped data has no empty weeks, so the previous row is always the previous calendar week.

Order matters: oldest week first.

Tables: tickets.

Learn the ideaRead the lesson →
solution.sqlDuckDB · helpdesk

Press ⌘ ↵ or Run to check the visible tests. Submit runs the hidden ones too. Everything runs in your browser.

⌘ ↵ to run