Given a Transactions table, find all customers who made the maximum number of transactions on consecutive days.
The table contains transaction information with unique (customer_id, transaction_date) combinations. You need to:
- Identify consecutive transaction days for each customer
- Count the maximum consecutive streak across all customers
- Return all customers who achieved this maximum streak
Return the result ordered by customer_id in ascending order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
transaction_id
PK
|
int | Unique identifier for each transaction |
customer_id
|
int | Customer identifier |
transaction_date
|
date | Date of the transaction |
amount
|
int | Transaction amount |
Input & Output
| transaction_id | customer_id | transaction_date | amount |
|---|---|---|---|
| 1 | 1 | 2023-01-01 | 150 |
| 2 | 1 | 2023-01-02 | 300 |
| 3 | 1 | 2023-01-03 | 200 |
| 4 | 2 | 2023-01-01 | 400 |
| 5 | 2 | 2023-01-02 | 250 |
| 6 | 3 | 2023-01-01 | 100 |
| customer_id |
|---|
| 1 |
Customer 1 has transactions on 3 consecutive days (2023-01-01, 2023-01-02, 2023-01-03). Customer 2 has transactions on 2 consecutive days. Customer 3 has only 1 transaction day. The maximum consecutive streak is 3, achieved only by Customer 1.
| transaction_id | customer_id | transaction_date | amount |
|---|---|---|---|
| 1 | 1 | 2023-01-01 | 100 |
| 2 | 1 | 2023-01-02 | 200 |
| 3 | 2 | 2023-01-03 | 300 |
| 4 | 2 | 2023-01-04 | 150 |
| 5 | 3 | 2023-01-01 | 250 |
| customer_id |
|---|
| 1 |
| 2 |
Both Customer 1 and Customer 2 have 2 consecutive transaction days, which is the maximum streak. Customer 3 has only 1 transaction day. Both customers with the maximum streak of 2 are returned.
Constraints
-
1 ≤ transaction_id ≤ 10^5 -
1 ≤ customer_id ≤ 10^4 -
transaction_dateis a valid date -
1 ≤ amount ≤ 10^6 -
Each
(customer_id, transaction_date)pair is unique