SQL interview question: Users who logged in three days in a row

hard
gaps and islands
ROW_NUMBER
CTE

Return the user_id of every user who logged in on at least three consecutive calendar days. A user can log in more than once a day.

Expected columns: user_id. Column names don't have to match. Runs on SQLite in your browser.

Tables: logins

CREATE TABLE logins (
  user_id INTEGER NOT NULL,
  login_date TEXT NOT NULL
);
INSERT INTO logins VALUES
  (1, '2026-01-01'), (1, '2026-01-02'), (1, '2026-01-02'), (1, '2026-01-03'),
  (2, '2026-01-01'), (2, '2026-01-03'), (2, '2026-01-04'),
  (3, '2026-01-05'), (3, '2026-01-06'), (3, '2026-01-07'), (3, '2026-01-08'),
  (4, '2026-01-10'),
  (5, '2026-01-20'), (5, '2026-01-21'), (5, '2026-01-23'), (5, '2026-01-24');

Your query

Ctrl/Cmd + Enter

FAQ