Skip to content

Repeat tickets from the same customer within a week

EasyFull bankSelf joinsDates and timeDeduplication and latest row12 min2 hidden datasets

The task

The support lead suspects some customers write in again because their first ticket was not solved. Find tickets that look like repeats.

A ticket B repeats an earlier ticket A when both have the same customer_id and the same category, and B was created (created_at) after A and at most 7 days (168 hours) after it. Exactly 168 hours still counts. Tickets created at exactly the same moment are not repeats of each other. If a customer opens three matching tickets within a week, every qualifying pair is reported.

Return first_ticket_id, repeat_ticket_id and hours_apart (hours between the two creation times, rounded to 1 decimal place). Sort by first_ticket_id, then repeat_ticket_id.

Expected output

first_ticket_idrepeat_ticket_idhours_apart
  • Sorted by first_ticket_id ascending, then repeat_ticket_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