AnalystPath

Tickets That Eventually Closed

SQLMediumMid level~15 min

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.

accounts
account_idcompanyplan
1Brightwave LabsPro
2Olive & CoBasic
3Tundra LogisticsEnterprise
ticket_events
event_idaccount_idlogged_onstatus
112024-03-04open
212024-03-12resolved
322024-03-01open

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

Related SQL questions