AnalystPath

Lead Climber on Each Route

SQLMediumMid level~15 min

Problem

A climbing gym assigns climbers to routes. Each climber has a recorded number of career ascents.

Table: route_assignment
+-------------+------+
| Column Name | Type |
+-------------+------+
| route_id | int |
| climber_id | int |
+-------------+------+
Each row says that the climber climber_id is assigned to route route_id. A pair (route_id, climber_id) is unique.

Table: climber
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| climber_id | int |
| handle | varchar |
| ascents | int |
+-------------+---------+
climber_id is the primary key. ascents is the climber's total number of completed ascents.

Write a solution that reports, for each route, the climber(s) with the highest number of ascents. If two or more climbers on the same route tie for the most ascents, report all of them. Return the result in any order with columns route_id and climber_id.

Tables

Example rows — the live problem includes the full dataset.

route_assignment
route_idclimber_id
11
12
13
climber
climber_idhandleascents
1Vega30
2Ridge20
3Crux30

Expected output

Your answer should return 3 rows with the columns route_id, climber_id.

Starter code (SQL)

SELECT *
FROM route_assignment;

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