How would you write a SQL solution for consecutive login days?
Write a PostgreSQL query that finds each user's longest streak of consecutive calendar days with at least one login. Multiple logins on the same day count once, and users without a valid login are excluded.
user_id, user_name, streak_start_date, streak_end_date, and consecutive_daysstreak_end_dateuser_id ascending| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique login event identifier |
| user_id | INT | User who generated the login event |
| login_at | TIMESTAMP | Timestamp when the login occurred |