Schema
Table
Setup
| Column Name | Type | Description |
|---|---|---|
| user_id | integer | User identifier. |
| subscription_type | varchar | Subscription plan. |
| last_active_date | date | Most recent watch date. |
Find users who have not watched any content in the last 30 days.
Schema
| Column Name | Type | Description |
|---|---|---|
| user_id | integer | User identifier. |
| subscription_type | varchar | Subscription plan. |
| last_active_date | date | Most recent watch date. |
Sample Data
| user_id | subscription_type | last_active_date |
|---|---|---|
| 101 | Premium | 2024-01-01 |
| 102 | Basic | 2024-02-20 |
| 103 | Standard | 2024-01-10 |
| 104 | Premium | 2024-02-15 |
| 105 | Basic | 2024-01-20 |
| 106 | Standard | 2024-02-25 |
| 107 | Premium | 2024-01-05 |
| user_id |
|---|
| 101 |
| 103 |
| 105 |
| 107 |
SQL Editor
| user_id |
|---|
| 101 |
| 103 |
| 105 |
| 107 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT user_id FROM users WHERE last_active_date < CURRENT_DATE - INTERVAL '30 days';
Explanation
Read each user's last_active_date.
Compare it with the current date minus 30 days.
Return users whose last activity is before that cutoff.
Related Questions