Return the user_id of users with strictly more than 3 transactions in 2024 and strictly more than 3 in 2025, sorted by user_id ascending. Users meeting the threshold in only one year are excluded.
Input Table(s)
Transactions (primary key transaction_id)
| Column | Type | Meaning |
|---|
| transaction_id | INT | Unique id of the transaction (primary key) |
| user_id | INT | User who made the transaction, NOT NULL |
| transaction_date | DATE | Date of the transaction, NOT NULL |
| amount | DECIMAL(10,2) | Transaction amount, non-negative, NOT NULL |
Output Contract
A single column, user_id (INT), with one row per qualifying user, sorted by user_id ascending. Each user appears at most once, so the order is unique. The result can be empty.
Example
Transactions
| transaction_id | user_id | transaction_date | amount |
|---|
| 1 | 201 | 2024-01-01 | 10.00 |
| 2 | 201 | 2024-02-01 | 10.00 |
| 3 | 201 | 2024-03-01 | 10.00 |
| 4 | 201 | 2024-04-01 | 10.00 |
| 5 | 201 | 2025-01-01 | 10.00 |
| 6 | 201 | 2025-02-01 | 10.00 |
| 7 | 201 | 2025-03-01 | 10.00 |
| 8 | 202 | 2024-01-15 | 25.00 |
| 9 | 202 | 2024-05-20 | 40.00 |
| 10 | 202 | 2024-08-02 | 15.00 |
| 11 | 202 | 2024-12-31 | 30.00 |
| 12 | 202 | 2025-01-01 | 20.00 |
| 13 | 202 | 2025-03-14 | 35.00 |
| 14 | 202 | 2025-06-30 | 10.00 |
| 15 | 202 | 2025-11-11 | 50.00 |
| 16 | 201 | 2026-01-05 | 10.00 |
Expected result:
User 201 has 4 transactions in 2024 (more than 3) but only 3 in 2025 (not more than 3), so they do not qualify. Their transaction on 2026-01-05 belongs to neither year and does not help. User 202 has 4 transactions in each year and qualifies.
Constraints and Clarifications
-
The table has between 1 and 100,000 rows.
-
transaction_id
is the unique primary key, so every row is one distinct transaction. There are no duplicate rows to remove.
-
user_id
is a positive integer and
amount
is non-negative. No column is NULL.
-
A year is the calendar year of
transaction_date
, from January 1 through December 31.
-
"Strictly more than 3" means at least 4 transactions in that year.
-
Each row counts as one transaction regardless of
amount
, including several transactions on the same day.
-
Transactions in years other than 2024 and 2025 are ignored.