Reactivated Users Per Month
Beginner Mode
Objective
You are given a table of user login records. Each row represents a single login event with the user ID and the date they logged in.
Table Schema:
The user_logins table:
| Column | Type | Description |
|---|---|---|
| user_id | integer | ID of the user |
| login_date | date | Date of the login |
Task Requirements:
- A reactivated user is one who logged in during the current month, did not log in during the previous month, but had logged in during some earlier month
- For each month, count the number of reactivated users
- Do not count brand new users who have no login history before the current month
- Months with zero reactivated users should not appear in the output
- Order the results by month in ascending order
Output columns: month, reactivated_users
Examples
Example 1:
Output:
Input:
| user_logins | |
|---|---|
| login_date | user_id |
| 2025-01-05 | 1 |
| 2025-01-15 | 1 |
| 2025-02-10 | 1 |
| 2025-04-08 | 1 |
| 2025-01-03 | 2 |
| 2025-03-12 | 2 |
| 2025-04-20 | 2 |
| 2025-01-10 | 3 |
| 2025-02-14 | 3 |
| 2025-03-05 | 3 |
| 2025-02-20 | 4 |
| 2025-04-15 | 4 |
| 2025-03-18 | 5 |
| 2025-04-25 | 5 |
| 2025-04-10 | 6 |
| month | reactivated_users |
|---|---|
| 2025-03-01 | 1 |
| 2025-04-01 | 2 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Spotify