About the “User Login Inactivity Gap with LEAD()” SQL Problem
Business Scenario
SaaS product engagement tracking requires detecting expanding gaps between user logins. An increasing interval between active sessions is the single strongest precursor to user churn.
Expected Output & Criteria
User login history with next session date and gap in days.
Database Table Schema (PostgreSQL DDL)
PostgreSQL 16 WASMThis challenge executes directly against the following relational schema in your browser:
CREATE TABLE user_logins (
login_id INT PRIMARY KEY,
user_id INT NOT NULL,
login_date DATE NOT NULL
);Target SQL Clauses & Operators
LEADOVERPARTITION BY
Want more Window Functions practice?
Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.