Users With 3 or More Consecutive Login Days
Preview mode. Log in to edit, run, submit, and save progress.
Users With 3 or More Consecutive Login Days
You are given a table of user login records. Each row records a user ID and the date they logged in. A user may have duplicate entries for the same date. Write a SQL query to find all user IDs who have logged in on at least 3 consecutive calendar days at any point. Duplicate login dates for the same user should be treated as a single login for that day. Return the result ordered by user_id. Table: Logins
| Column Name | Type | Description |
|---|---|---|
| user_id | INT | ID of the user |
| login_date | DATE | Date the user logged in |
Examples
User 1 logged in on Jan 1, 2, 3 - 3 consecutive days. User 2 skipped Jan 2. User 3 logged in on 4 consecutive days. Users 1 and 3 qualify.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.