Members With a Quick Repeat Borrow
Problem
Table: `borrow_log`
| Column Name | Type |
|---|---|
| member_id | int |
| title | varchar |
| borrowed_on | date |
| fee_cents | int |
There is no primary key; a member may borrow several titles, and the same member can appear on many dates. Each row records a single borrow event.
A member is *engaged* if they have two borrow events whose dates are 7 days apart or less (consecutive in time for that member). Report the `member_id` of every engaged member, each id once. Return them in any order.
Tables
Example rows — the live problem includes the full dataset.
| member_id | title | borrowed_on | fee_cents |
|---|---|---|---|
| 5 | Tide Tables | 2022-04-01 | 0 |
| 5 | Marsh Birds | 2022-04-05 | 0 |
| 6 | Clay Sculpting | 2022-04-01 | 50 |
Expected output
Your answer should return 1 row with the columns member_id.
Starter code (SQL)
SELECT *
FROM borrow_log;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