AnalystPath

Next-Day Return Rate at a Climbing Gym

SQLMediumMid level~15 min

Problem

Table: `GymVisit`

```text
+--------------+---------+
| Column | Type |
+--------------+---------+
| climber_id | int |
| wall_id | int |
| visit_day | date |
| routes_done | int |
+--------------+---------+
(climber_id, visit_day) is the primary key. Each row records that a climber visited the gym on a given day, used some wall, and completed some number of routes (possibly 0).
```

Report the **fraction** of climbers who came back on the day immediately after their very first visit. That is: among all climbers, how many had a visit on the calendar day right after their earliest visit day, divided by the total number of distinct climbers. Round the result to **2 decimal places** and label the column `return_rate`.

**Example**

```text
GymVisit:
+------------+---------+------------+-------------+
| climber_id | wall_id | visit_day | routes_done |
+------------+---------+------------+-------------+
| 7 | 2 | 2021-04-01 | 4 |
| 7 | 2 | 2021-04-02 | 6 |
| 8 | 3 | 2022-09-10 | 1 |
| 9 | 1 | 2021-04-02 | 0 |
| 9 | 5 | 2023-01-15 | 3 |
+------------+---------+------------+-------------+

Output:
+-------------+
| return_rate |
+-------------+
| 0.33 |
+-------------+
```

Only climber 7 returned on the day after their first visit (Apr 1 → Apr 2), so the answer is 1 / 3 = 0.33.

Tables

Example rows — the live problem includes the full dataset.

GymVisit
climber_idwall_idvisit_dayroutes_done
722021-04-014
722021-04-026
832022-09-101

Expected output

Your answer should return 1 row with the columns return_rate.

Starter code (SQL)

SELECT *
FROM GymVisit;

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