GitLab wants to monitor whether Premium subscribers continue using GitLab in the following week. Login activity must be evaluated against the subscriber's tier at the time of each login.
Write a PostgreSQL query that calculates weekly retention for Premium users.
DATE_TRUNC('week', ...).premium tier at the time of the login.NULL for the final week when no following week is available.| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique login event identifier |
| user_id | INT | GitLab user identifier |
| login_at | TIMESTAMP | Timestamp when the user logged in |
| Column | Type | Description |
|---|---|---|
| subscription_idPK | INT | Unique subscription record identifier |
| user_id | INT | GitLab user identifier |
| tier | VARCHAR(20) | Subscription tier |
| valid_from | TIMESTAMP | Start of the tier period |
| valid_to | TIMESTAMP | Exclusive end of the tier period, or NULL for an active period |