Write a query using window functions and conditional aggregations to identify potential duplicate transactions occurring within a 5-minute window.
Treat transactions with the same non-null account, merchant, amount, and currency as potential duplicates. Only completed transactions count toward duplicate detection, and the five-minute boundary is inclusive.
transaction_id, transaction attributes, previous_completed_transaction_id, and duplicate_count.occurred_at, then transaction_id.| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Account that initiated the transaction |
| merchant_id | VARCHAR(30) | Merchant receiving the transaction |
| amount | NUMERIC(12,2) | Transaction amount |
| currency | VARCHAR(3) | Three-letter transaction currency |
| occurred_at | TIMESTAMPTZ | Transaction event timestamp |
| status | VARCHAR(20) | Transaction processing status |