How would you use SQL window functions like LEAD and LAG to analyze user churn over time?
Use the users and activity_events tables. Return one row for each user and month in which the user was active, identifying the previous and next active months and whether the user churned after that month.
user_id, active_month, previous_active_month, next_active_month, and churned_after_monthuser_id, then active_month| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| signup_date | DATE | Date the user registered |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique activity event identifier |
| user_id | INT | User associated with the event |
| event_at | TIMESTAMP | Timestamp when the activity occurred |
| event_type | VARCHAR(50) | Optional activity category |