Members Who Held a Pass but Never Checked In
Problem
Table: `passes`
| Column Name | Type |
|---|---|
| member_id | int |
| valid_from | date |
| valid_to | date |
There is no unique single column. Each row is a gym pass a member held between `valid_from` and `valid_to` inclusive.
Table: `checkins`
| Column Name | Type |
|---|---|
| member_id | int |
| visit_date | date |
There is no unique single column. Each row records a day a member entered the gym.
Count how many distinct members held a pass that was valid at any point during the year 2022 (the pass overlaps the window 2022-01-01 to 2022-12-31) yet never checked in during 2022. Return one column named `inactive_members`.
Tables
Example rows — the live problem includes the full dataset.
| member_id | valid_from | valid_to |
|---|---|---|
| 1 | 2022-03-01 | 2022-09-01 |
| 2 | 2021-06-01 | 2022-02-01 |
| 3 | 2020-01-01 | 2020-12-31 |
| member_id | visit_date |
|---|---|
| 1 | 2022-04-10 |
| 2 | 2021-07-01 |
Expected output
Your answer should return 1 row with the columns inactive_members.
Starter code (SQL)
SELECT *
FROM passes;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