Skip to content

Average satisfaction score by channel

MediumFull bankNULL handlingJoinsGroup and aggregate10 min2 hidden datasets

The task

The support lead wants the average satisfaction score by channel. Not every ticket gets a survey answer: satisfaction has at most one row per ticket, and many tickets have none. A ticket with no answer has no score, which is not the same as a score of 0, so it must not drag the average down.

For every channel that has at least one ticket, return:

  • channel
  • tickets, the number of tickets in the channel
  • answers, the number of tickets with a survey answer
  • avg_score, the average score of the answers, rounded to 2 decimal places

A channel with no answers has no average, so return NULL for avg_score. Sort by channel ascending.

Expected output

channelticketsanswersavg_score
  • Sorted by channel ascending.
  • Numbers rounded to 2 decimal places.
  • 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