Compute Monthly Active Users. A user is active in a month if they performed at least one 'commit', 'push' or 'merge_request' activity that month. Other activity types are ignored.
Input Table(s)
user_activities (primary key id)
| Column | Type | Meaning |
|---|
| id | INT | Activity identifier |
| user_id | INT | User who performed the activity, NOT NULL |
| activity_type | VARCHAR(50) | Kind of activity, such as 'commit' or 'login', NOT NULL |
| activity_date | DATE | Day of the activity, NOT NULL |
Output Contract
-
Columns, in this order:
month
(text formatted
YYYY-MM
) and
active_users
(count of distinct users).
-
One row per month that has at least one qualifying activity.
-
Order by
month
ascending.
Example
user_activities
| id | user_id | activity_type | activity_date |
|---|
| 1 | 101 | commit | 2024-01-05 |
| 2 | 102 | push | 2024-01-10 |
| 3 | 101 | push | 2024-01-15 |
| 4 | 103 | merge_request | 2024-02-01 |
| 5 | 101 | commit | 2024-02-14 |
| 6 | 104 | login | 2024-02-20 |
| 7 | 102 | commit | 2024-02-25 |
| 8 | 105 | browse | 2024-01-18 |
Expected result:
| month | active_users |
|---|
| 2024-01 | 2 |
| 2024-02 | 3 |
In January, users 101 and 102 qualify. User 101 has two qualifying rows but counts once, and user 105 only browsed. In February, users 101, 102 and 103 qualify, and user 104 only logged in.
Constraints and Clarifications
-
The table has 1 to 10,000 rows.
-
activity_type
can be any string. Only the exact values
'commit'
,
'push'
and
'merge_request'
qualify.
-
A user can have multiple activities on the same day or in the same month.
-
The same calendar month in different years is a different month (
2024-01
and
2025-01
are separate rows).
-
A month whose activities are all of other types does not appear in the output.