AnalystPath

Members Who Held a Pass but Never Checked In

SQLMediumMid level~15 min

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.

passes
member_idvalid_fromvalid_to
12022-03-012022-09-01
22021-06-012022-02-01
32020-01-012020-12-31
checkins
member_idvisit_date
12022-04-10
22021-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

Related SQL questions