Repeated Payment Transactions
Beginner Mode
Objective
You are given a table of credit card transactions. Each row represents a single payment with details about the merchant, credit card, amount, and timestamp.
Table Schema:
The transactions table:
| Column | Type | Description |
|---|---|---|
| transaction_id | integer | Unique ID for each transaction |
| merchant_id | integer | ID of the merchant |
| credit_card_id | integer | ID of the credit card used |
| amount | decimal | Payment amount in dollars |
| transaction_timestamp | timestamp | Date and time of the transaction |
Task Requirements:
- Identify transactions that occur at the same merchant, with the same credit card and same amount, within 10 minutes of the previous matching transaction
- Count the number of such repeated payments, ignoring the first transaction in each sequence
- Use the
LAG()window function partitioned by merchant, credit card, and amount
Output columns: payment_count
Examples
Example 1:
Output:
Input:
| transactions | ||||
|---|---|---|---|---|
| amount | credit_card_id | merchant_id | transaction_id | transaction_timestamp |
| 50 | 1 | 1 | 1 | 2025-01-15 10:00:00 |
| 50 | 1 | 1 | 2 | 2025-01-15 10:08:00 |
| 50 | 1 | 1 | 3 | 2025-01-15 10:30:00 |
| 100 | 2 | 2 | 4 | 2025-01-15 11:00:00 |
| 100 | 2 | 2 | 5 | 2025-01-15 11:05:00 |
| 50 | 2 | 1 | 6 | 2025-01-15 12:00:00 |
| 75 | 1 | 1 | 7 | 2025-01-15 10:05:00 |
| payment_count |
|---|
| 2 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Stripe