Premium problem57. 95th Percentile API Latency

Hard Locked

api_requests(request_id, endpoint, latency_ms, requested_at)

For each endpoint in September 2026, return the request count and the 95th percentile latency.

Use the nearest-rank definition: sort the latencies ascending and take the value at position CEIL(0.95 * n). For small n that is simply the slowest request, which is the honest answer rather than an interpolated one.

Return endpoint, request_count and p95_latency_ms, ordered by endpoint.

Tables

api_requests

request_id  endpoint  latency_ms  requested_at
----------  --------  ----------  -------------------
1           /search   10          2026-09-01 00:00:00
2           /search   20          2026-09-01 00:00:00
3           /search   30          2026-09-01 00:00:00
4           /search   40          2026-09-01 00:00:00
5           /search   50          2026-09-01 00:00:00
6           /search   60          2026-09-01 00:00:00
7           /search   70          2026-09-01 00:00:00
8           /search   80          2026-09-01 00:00:00
... 16 more row(s)

Expected result

endpoint  request_count  p95_latency_ms
--------  -------------  --------------
/ping     3              9
/search   20             190

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query