Skip to content

Tickets per agent, including unassigned ones

MediumFull bankNULL handlingJoinsGroup and aggregate12 min2 hidden datasets

The task

The support lead wants the workload on one list: how many tickets each agent has, how many are waiting with no agent at all, and which agents have nothing.

Return:

  • agent_id, the agent's id, or NULL for the row that counts unassigned tickets (tickets.agent_id is NULL)
  • tickets, the number of tickets assigned to that agent, or the number of unassigned tickets on the NULL row

Include every agent in agents, with 0 tickets if they have none. Include the NULL row only when there is at least one unassigned ticket. Sort by agent_id ascending with NULL last.

Expected output

agent_idtickets
  • Sorted by agent_id 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