Daily open ticket backlog

mediumSQL~25 min · 4 tests · helpdesk

The support lead wants a backlog chart: for each day, how many tickets were still open when the day ended. A ticket is open on a day if it was opened that day or earlier, and it hadn’t been closed by the end of that day.

Use dates, not times:

  • A ticket counts on day when opened_at’s date is on or before day, and either closed_at is NULL or closed_at’s date is after day.
  • A ticket opened and closed on the same day never counts.
  • A ticket closed at exactly midnight belongs to the day that starts at that midnight, so it still counts as open on the day before.

Return one row for every calendar day from the earliest opened_at date to the latest opened_at date, inclusive:

column type meaning
day date the calendar day
open_tickets integer tickets open at the end of that day; 0 if none

Sort by day, oldest first. Order matters.

Tables: tickets.

solution.sqlDuckDB · helpdesk

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

⌘ ↵ to run