Hours since the customer's previous ticket
The task
The support lead wants to know how quickly customers come back. For every ticket created in June 2025 (from 2025-06-01 up to, but not including, 2025-07-01), find how long it had been since the same customer's previous ticket.
The previous ticket is the customer's latest ticket with an earlier created_at. If two tickets of one customer share the same created_at, the one with the lower ticket_id comes first. The previous ticket can be from any month. Tickets that are the customer's first ever are left out.
Return:
ticket_idcustomer_idcreated_athours_since_previous: the total hours between the previous ticket'screated_atand this one's, as a number rounded to 1 decimal place (days count as 24 hours each)
Sort by created_at, then ticket_id.
Expected output
ticket_idcustomer_idcreated_athours_since_previous- Sorted by created_at ascending, then 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
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL