Skip to content

Agent by month fact table of tickets created and resolved

The task

Support leaders want a monthly scorecard at the grain one row per agent per calendar month, for February to June 2025.

  • An agent has a row for a month when hired_on is before the first day of the next month. Agents are never removed.
  • tickets_created: tickets assigned to the agent (tickets.agent_id) with created_at in that month.
  • tickets_resolved: tickets assigned to the agent with resolved_at in that month. A ticket can be created in one month and resolved in a later one, and it counts in each month for its own event. Tickets with no resolved_at are never counted as resolved.
  • A month with no tickets of a kind shows 0.

Return agent_id, month (the first day of the month), tickets_created and tickets_resolved. Sort by agent_id, then month.

Expected output

agent_idmonthtickets_createdtickets_resolved
  • Sorted by agent_id ascending, then month ascending.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables Customer support desk · click a name to insert it

agents14 rows in the sample

Support agents. Key: agent_id.

intUnique id.
textName.
textbilling, technical or general.
dateStart day.
tickets900 rows in the sample

One row per ticket. Key: ticket_id.

intUnique id.
intWho opened it.
intAssigned agent. NULL if never assigned.
textemail, chat or phone.
textlow, normal, high or urgent.
textbilling, bug, how_to or account.
timestampOpened (UTC).
timestampFirst reply from an agent. NULL if none yet.
timestampClosed as solved. NULL while open.
satisfaction366 rows in the sample

Survey answers, at most one per ticket. Key: ticket_id.

intThe ticket.
int1 (very unhappy) to 5 (very happy).
timestampWhen answered (UTC).

Related questions

Loading the editor and PostgreSQL