Members Active in Two Quarters
Problem
A gym tracks every class booking. Each booking links a member to a class, and each class has a credit cost.
Write a query to find the members who spent **at least 50 credits in Q1 2023 (Jan-Mar) AND at least 50 credits in Q2 2023 (Apr-Jun)**. The credits for a booking are `seats * cost`.
Return `member_id` and `member_name`. Order does not matter.
Tables
Example rows — the live problem includes the full dataset.
members
| member_id | member_name | home_city |
|---|---|---|
| 1 | Priya | Austin |
| 2 | Diego | Lima |
| 3 | Hana | Osaka |
classes
| class_id | class_title | cost |
|---|---|---|
| 10 | Spin | 150 |
| 20 | Yoga | 5 |
| 30 | Boxing | 22 |
bookings
| booking_id | member_id | class_id | booked_on | seats |
|---|---|---|---|---|
| 1 | 1 | 10 | 2023-02-10 | 1 |
| 2 | 1 | 20 | 2023-04-01 | 1 |
| 3 | 1 | 30 | 2023-04-08 | 3 |
Expected output
Your answer should return 1 row with the columns member_id, member_name.
Starter code (SQL)
SELECT *
FROM members;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