Skip to content
BytePatterns

Logged In Three Days in a Row

MediumSQL#window-function#consecutive-rows#dedupe~25m

Problem

A table login(person, day) gets one row every time someone signs in, with day stored as a YYYY-MM-DD date, and a person can sign in several times on the same day. Write a query that returns every person who signed in on at least three consecutive calendar days, as a single column person, sorted, with each person listed once.

Examples

Input:  login = [("kim", "2026-09-01"), ("kim", "2026-09-02"), ("kim", "2026-09-03"), ("lee", "2026-09-01"), ("lee", "2026-09-02"), ("lee", "2026-09-04")]
Output: [("kim",)]
Why:    lee misses 09-03, so lee never has three days in a row
Input:  login = [("max", "2026-09-01"), ("max", "2026-09-02"), ("max", "2026-09-02"), ("max", "2026-09-03")]
Output: [("max",)]
Why:    signing in twice on 09-02 must not hide the streak
Input:  login = [("ria", "2026-08-31"), ("ria", "2026-09-01"), ("ria", "2026-09-02")]
Output: [("ria",)]
Why:    edge case, a streak can cross the end of a month

Hints

0 / 3

Stuck on the idea rather than the code? Window Functions covers it.