AnalystPath

Same-Day Rate on First Tickets

SQLMediumMid level~15 min

Problem

Table: `Requests`

```text
+-------------+---------+
| Column | Type |
+-------------+---------+
| request_id | int |
| client_id | int |
| opened_on | date |
| resolved_on | date |
+-------------+---------+
request_id is the primary key. Each row is one support request. A client may
file many requests.
```

Consider only each client's **first request** (their earliest `opened_on`).
Among those first requests, return the percentage that were resolved on the
same day they were opened, rounded to 2 decimal places. Use the column
heading `same_day_pct`. Assume each client's first open date is unique.

**Example**

```text
Requests:
+------------+-----------+------------+-------------+
| request_id | client_id | opened_on | resolved_on |
+------------+-----------+------------+-------------+
| 1 | 7 | 2024-01-01 | 2024-01-01 |
| 2 | 7 | 2024-02-01 | 2024-02-05 |
| 3 | 8 | 2024-01-10 | 2024-01-12 |
+------------+-----------+------------+-------------+

Output:
+--------------+
| same_day_pct |
+--------------+
| 50.0 |
+--------------+
```

Client 7's first request (request 1) was same-day; client 8's first request
(request 3) was not. Among the two first requests, one is same-day = 50.0%.

Tables

Example rows — the live problem includes the full dataset.

Requests
request_idclient_idopened_onresolved_on
172024-01-012024-01-01
272024-02-012024-02-05
382024-01-102024-01-12

Expected output

Your answer should return 1 row with the columns same_day_pct.

Starter code (SQL)

SELECT *
FROM Requests;

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