Your question is Group By and Having for Duplicates. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Systems Planning and Analysis needs to audit records in its transaction ledger for duplicate business events received from multiple ingestion sources. Write a PostgreSQL query that identifies duplicate transaction groups without relying on the unique transaction_id.
account_number, transaction_date, merchant_code, amount, and currency.GROUP BY and HAVING COUNT(*) > 1 to find duplicate groups.source_id has no matching source record.merchant_code values as equal for duplicate detection.| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction record ID |
| account_number | VARCHAR(20) | SPA ledger account reference |
| transaction_date | DATE | Business transaction date |
| merchant_code | VARCHAR(20) | Merchant identifier |
| amount | NUMERIC(12,2) | Transaction amount |
| currency | VARCHAR(3) | ISO currency code |
| source_id | INT | Ingestion source reference |
| Column | Type | Description |
|---|---|---|
| source_idPK | INT | Source identifier |
| source_name | VARCHAR(80) | Ingestion source name |