Repeat tickets from the same customer within a week
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.
| int | Unique id. | |
| text | Name. | |
| text | billing, technical or general. | |
| date | Start day. |
tickets900 rows in the sample
One row per ticket. Key: ticket_id.
| int | Unique id. | |
| int | Who opened it. | |
| int | Assigned agent. NULL if never assigned. | |
| text | email, chat or phone. | |
| text | low, normal, high or urgent. | |
| text | billing, bug, how_to or account. | |
| timestamp | Opened (UTC). | |
| timestamp | First reply from an agent. NULL if none yet. | |
| timestamp | Closed as solved. NULL while open. |
satisfaction366 rows in the sample
Survey answers, at most one per ticket. Key: ticket_id.
| int | The ticket. | |
| int | 1 (very unhappy) to 5 (very happy). | |
| timestamp | When answered (UTC). |
Related questions
- Colleagues hired in the same month and departmenteasy
- Users whose carts turn into purchases within 30 minutesmedium
- Employees paid more than their managermedium
- How many drivers in the same city rate higherhard
- Products bought together in the same ordermedium
- Raises of 9.5 percent or more over the previous salaryhard
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL