Back to Practice
#0159

Monthly Active Users

MediumSQL25 min20 XP

Problem

Given events(user_id, event_date), return month and distinct active users per month.

Why This Matters

MAU is one of the simplest product metrics, but duplicate events can inflate it if DISTINCT is forgotten.

Schema

events(user_id INTEGER, event_date TEXT)

Examples

Example 1
Inputuser 1 has two January events; user 2 has one February event
Output2026-01 -> 1, 2026-02 -> 1

Multiple events by the same user in a month count once.

Constraints

  • Return the exact requested value.
  • Handle empty or small inputs when the prompt allows them.
  • Keep the code readable and deterministic.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputuser 1 has two January events; user 2 has one February event
Expected2026-01 -> 1, 2026-02 -> 1

Multiple events by the same user in a month count once.

Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input