Back to Practice
#0359

Users With Consecutive Login Days

MediumSQL24 min20 XP

Problem

Return user_id values that have logins on two consecutive calendar days.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

logins(user_id INTEGER, login_date TEXT)

Examples

Example 1
Inputuser 1 logged in Jan 1 and Jan 2
Outputuser 1

The self-join checks for the next calendar day.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputuser 1 logged in Jan 1 and Jan 2
Expected[[1]]

The self-join checks for the next calendar day.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks