Users Active in Both January and February
Problem statement
The activity table records user activity events. Each row counts as one activity, and activity_date is a calendar date with no time or timezone conversion.
Find every user who has at least one activity in January 2025 and at least one activity in February 2025. Return one user_id row per qualifying user, sorted by user_id in ascending order.
Repeated events on the same date count as activity, but must not create duplicate result rows. Activity outside those two months, including the same months in another year, does not count.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
activity
One row per user activity event.
| Column | Type | Nullable | Description |
|---|---|---|---|
| event_idPK | Integer | No | — |
| user_id | Integer | No | — |
| activity_date | Date | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_id | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The table contains between 0 and 10^4 rows.
event_idis unique and between 1 and 10^9.user_idis an integer between 1 and 10^9.activity_dateis a valid date between2020-01-01and2030-12-31.