Agent Resolution Rate
Problem
A help desk tracks its support agents and the outcome of each ticket they handle.
Table: agents
| Column Name | Type |
|-------------|----------|
| agent_id | int |
| hired_at | datetime |
agent_id is the unique key for this table. Each row records when an agent was hired.
Table: tickets
| Column Name | Type |
|-------------|----------|
| agent_id | int |
| opened_at | datetime |
| outcome | text |
(agent_id, opened_at) is the primary key for this table. agent_id references the agents table. outcome is one of 'resolved' or 'escalated'. Each row is one ticket the agent handled and how it ended.
An agent's resolution rate is the number of 'resolved' tickets divided by the total number of tickets they handled. An agent who handled no tickets has a resolution rate of 0. Round the rate to two decimal places.
Return agent_id and resolution_rate for every agent, in any order.
Tables
Example rows — the live problem includes the full dataset.
| agent_id | hired_at |
|---|---|
| 3 | 2020-03-21 10:16:13 |
| 7 | 2020-01-04 13:57:59 |
| 2 | 2020-07-29 23:09:44 |
| agent_id | opened_at | outcome |
|---|---|---|
| 3 | 2021-01-06 03:30:46 | escalated |
| 3 | 2021-07-14 14:00:00 | escalated |
| 7 | 2021-06-12 11:57:29 | resolved |
Expected output
Your answer should return 4 rows with the columns agent_id, resolution_rate.
Starter code (SQL)
SELECT *
FROM agents;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