Skip to content

Repeat contact within 14 days of a first ticket

HardFull bankRanking and top NDates and timeJoins22 min2 hidden datasets

The task

The support lead suspects some first-time issues are not really solved, because the customer comes back. For every customer who has opened at least one ticket, find their first ticket (the earliest created_at; if two tickets share the same created_at, the lower ticket_id is first) and their second ticket (the next one in the same order, if any).

A customer is a repeat customer when their second ticket was created no later than 14 days after the first one, counted as first.created_at + interval '14 days' (exactly 14 days later still counts).

Group customers by the category of their first ticket. Return category, customers (customers whose first ticket has that category) and repeat_customers (how many of them are repeat customers). Sort by category ascending.

Expected output

categorycustomersrepeat_customers
  • Sorted by category 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