AnalystPath

Agent Resolution Rate

SQLMediumMid level~15 min

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.

agents
agent_idhired_at
32020-03-21 10:16:13
72020-01-04 13:57:59
22020-07-29 23:09:44
tickets
agent_idopened_atoutcome
32021-01-06 03:30:46escalated
32021-07-14 14:00:00escalated
72021-06-12 11:57:29resolved

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

Related SQL questions