Write a SQL query to identify duplicate records in a large dataset across multiple tables.
Use the supplied transaction, account, and channel data. Treat transactions with the same account, date, amount, merchant, and channel as duplicates. Exclude transactions whose account or channel cannot be matched.
Output
- One row per duplicated business key
- Columns:
account_id, transaction_date, amount, merchant_name, channel_name, duplicate_count, and transaction_ids
- Include only keys occurring more than once
- Order by
account_id, transaction_date, amount, merchant_name, and channel_name
Output details
- Sort all listed ordering columns in ascending order, placing
NULL transaction_date values last.
- Aggregate
transaction_ids in ascending numeric order, separated by ', '.
- Treat
NULL values in business-key columns as belonging to the same duplicate group.