Write a query to identify duplicates in a large dataset while optimizing for performance.
Treat records with the same source_system, trade_reference, trade_date, and notional as duplicates. NULL values within these columns should be treated as equal duplicate-key values.
source_system, trade_reference, trade_date, notional, and duplicate_count.duplicate_count descending, then the key columns ascending with NULL values last.| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique trade event identifier |
| source_system | VARCHAR(40) | System that supplied the trade event |
| trade_reference | VARCHAR(40) | Source trade reference |
| trade_date | DATE | Trade business date |
| notional | NUMERIC(18,2) | Trade notional amount |