AnalystPath

Percentile Standing of Each Runner

SQLMediumMid level~15 min

Problem

A race series records finishing times converted to a score, grouped by age bracket. Table `runners` has columns `(runner_id, bracket_id, score)` where a higher score is better.

Within each age bracket, express each runner's standing as a percentage using the formula `(rank - 1) * 100 / (total_runners - 1)`, where `rank` is the runner's position by score (highest score is rank 1, ties share a rank), and `total_runners` is how many runners are in that bracket. The best runner gets 0 and the worst gets 100. If a bracket has only one runner, report 0. Round the result to 2 decimal places.

Return the columns `runner_id`, `bracket_id`, and `standing`.

Tables

Example rows — the live problem includes the full dataset.

runners
runner_idbracket_idscore
22650
82650
71920

Expected output

Your answer should return 5 rows with the columns runner_id, bracket_id, standing.

Starter code (SQL)

SELECT *
FROM runners;

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