AnalystPath

Members With a Quick Repeat Borrow

SQLMediumMid level~15 min

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.

borrow_log
member_idtitleborrowed_onfee_cents
5Tide Tables2022-04-010
5Marsh Birds2022-04-050
6Clay Sculpting2022-04-0150

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

Related SQL questions