Back to Practice
#0369

Reactivated Users After Long Gap

HardSQL35 min25 XP

Problem

Return user_id values that have a gap of more than 30 days between consecutive events.

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

events(user_id INTEGER, event_date TEXT)

Examples

Example 1
Inputuser 1 has a 35 day gap
Outputuser 1

LAG exposes the previous event date per user.

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 has a 35 day gap
Expected[[1]]

LAG exposes the previous event date per user.

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