P90 Response Time

Hard SQLWindowNTILEPercentile

Problem

Schema: Request(endpoint VARCHAR, ms INT). For each endpoint, return the 90th percentile of ms. Use PERCENTILE_CONT(0.9) (or PERCENTILE_DISC(0.9)) if your dialect has it; otherwise compute via ordered position.

Example 1 Input: endpoint /a: ms = 10, 20, 30, 40, 50 Output: (/a, 46.0) -- linear interpolation

Constraints

Approach — Core Patterns

This is a Core Patterns problem. The idea: pick the data structure best matched to the constraints and solve it in one clean pass. Work through the reference code below line by line, then re-derive it yourself in the editor — that's how the pattern sticks.

Complexity: see the walkthrough below.

Solution code

SQL

SELECT endpoint,
       PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY ms) AS p90
FROM Request
GROUP BY endpoint
ORDER BY endpoint;

Practice it

Reading a solution isn't the same as being able to write it under pressure. Open this problem in the in-browser editor, hide the solution, and solve it from scratch — your code runs against real test cases instantly.

Solve P90 Response Time interactively → ← All solutions