Monthly active users from commit, push and merge request activity

Quick Overview

Write a SQL query that counts monthly active users, where a user is active in a month if they made at least one commit, push or merge request. It tests filtering before aggregation, counting distinct users per group and formatting dates as year-month labels that sort correctly.

Monthly active users from commit, push and merge request activity

Company: GitLab

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

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. ```hint Count people, not rows A single user can have several qualifying activities in the same month. Make sure each user adds at most 1 to that month's number. ``` ### 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.

Overview: Write a SQL query that counts monthly active users, where a user is active in a month if they made at least one commit, push or merge request. It tests filtering before aggregation, counting distinct users per group and formatting dates as year-month labels that sort correctly.

GitLab logo
GitLab
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

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)

ColumnTypeMeaning
idINTActivity identifier
user_idINTUser who performed the activity, NOT NULL
activity_typeVARCHAR(50)Kind of activity, such as 'commit' or 'login', NOT NULL
activity_dateDATEDay 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

iduser_idactivity_typeactivity_date
1101commit2024-01-05
2102push2024-01-10
3101push2024-01-15
4103merge_request2024-02-01
5101commit2024-02-14
6104login2024-02-20
7102commit2024-02-25
8105browse2024-01-18

Expected result:

monthactive_users
2024-012
2024-023

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.