Skip to content

Categories behind each agent's unhappy surveys

MediumFull bankGroup and aggregateJoinsText and set operations12 min2 hidden datasets

The task

The support manager is preparing one-to-one meetings. For each agent she wants to see which ticket categories ended in an unhappy customer.

An unhappy ticket is a ticket with a row in satisfaction whose score is 1 or 2. It belongs to the agent in tickets.agent_id. Tickets with no agent are ignored.

Return one row for every agent in agents:

  • agent_id
  • full_name
  • unhappy_tickets: the number of unhappy tickets (0 if none)
  • categories: the different ticket categories of those tickets, sorted alphabetically and joined with a comma and a space (for example account, bug), or NULL when the agent has no unhappy ticket

Sort by agent_id ascending.

Expected output

agent_idfull_nameunhappy_ticketscategories
  • 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