Tickets That Eventually Closed
Problem
A help desk logs status events for each customer account. Find every account whose ticket was opened and later resolved: there must be an 'open' event followed by at least one 'resolved' event on a strictly later date. Report the resolution time as the number of days between the first 'open' event and the first 'resolved' event that comes after it. Sort by resolution time ascending, then by company name alphabetically.
Tables
Example rows — the live problem includes the full dataset.
| account_id | company | plan |
|---|---|---|
| 1 | Brightwave Labs | Pro |
| 2 | Olive & Co | Basic |
| 3 | Tundra Logistics | Enterprise |
| event_id | account_id | logged_on | status |
|---|---|---|---|
| 1 | 1 | 2024-03-04 | open |
| 2 | 1 | 2024-03-12 | resolved |
| 3 | 2 | 2024-03-01 | open |
Expected output
Your answer should return 3 rows with the columns company, days_to_close.
Starter code (SQL)
SELECT *
FROM accounts;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock