Repeat contact within 14 days of a first ticket
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.
| 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
- Average first purchase value by campaign, organic includedmedium
- Best seller on each sales channel in the first quartermedium
- Each customer's largest single expense, with tie-breakersmedium
- Favourite spending category per customer, counted by segmenthard
- Genre of each listener's first playmedium
- Months each merchant ranked in the top three for spendmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL