Skip to content

Agent share of their team's tickets

EasyFull bankCTEs and subqueriesRatios and percentages10 min2 hidden datasets

The task

The support lead wants to see how evenly work is spread inside each team. A ticket belongs to its assigned agent (tickets.agent_id); tickets with no assigned agent belong to nobody and are ignored.

Return one row per agent, including agents with no tickets:

  • agent_id
  • full_name
  • team
  • tickets: tickets assigned to the agent
  • team_tickets: tickets assigned to any agent on the same team
  • pct_of_team: tickets as a percentage of team_tickets, rounded to 1 decimal place

Sort by team and then agent_id. Every team in the data has at least one ticket.

Expected output

agent_idfull_nameteamticketsteam_ticketspct_of_team
  • Sorted by team ascending, then agent_id ascending.
  • Numbers rounded to 1 decimal place.
  • 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