Table Schema
Inspect
Table
| Column | Type |
|---|---|
| ticket_id | integer |
| category | varchar |
| created_at | datetime |
| resolved_at | datetime |
Calculate average resolution time per support category.
Table Schema
| Column | Type |
|---|---|
| ticket_id | integer |
| category | varchar |
| created_at | datetime |
| resolved_at | datetime |
Sample Data
| ticket_id | category | created_at | resolved_at |
|---|---|---|---|
| 1 | Billing | 09:00 | 10:00 |
| 2 | Tech | 10:00 | 12:00 |
| 3 | Billing | 11:00 | 12:00 |
| 4 | Tech | 13:00 | 15:00 |
| 5 | Account | 14:00 | 16:00 |
| category | avg_resolution_time |
|---|---|
| Account | 2 hours |
| Billing | 1 hour |
| Tech | 2 hours |
SQL Editor
| category | avg_resolution_time |
|---|---|
| Account | 2 hours |
| Billing | 1 hour |
| Tech | 2 hours |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT category, AVG(resolved_at - created_at) AS avg_resolution_time FROM tickets GROUP BY category;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions