Write a SQL query to find duplicate transaction records in a ledger table.
Treat records as duplicates when their account, transaction type, amount, currency, transaction date, and reference code match. The reference code may be NULL, and NULL reference codes should match other NULL reference codes. Return every record belonging to a duplicate group.
transaction_id, account_id, transaction_type, amount, currency, transaction_date, reference_code, and duplicate_countaccount_id, transaction_date, and transaction_id ascending| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique ledger record identifier |
| account_id | INT | Account associated with the transaction |
| transaction_type | VARCHAR(20) | Ledger transaction classification |
| amount | NUMERIC(12,2) | Transaction amount |
| currency | VARCHAR(3) | Three-letter transaction currency |
| transaction_date | DATE | Date the transaction was recorded |
| reference_code | VARCHAR(30) | External or internal transaction reference |