SQLRepPath
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
00/60 solved

Interview Drills · GROUP BY · HAVING to find duplicates

27. Duplicate card charges

Concept: GROUP BY · HAVING to find duplicatesshow

To find duplicates, GROUP BY every column that defines 'the same thing' and keep groups with HAVING COUNT(*) > 1. Leaving a column out merges rows that aren't really duplicates.

Example (different data):

SELECT email, COUNT(*) AS copies
FROM signups
GROUP BY email
HAVING COUNT(*) > 1;

Your task

Fintech support keeps hearing 'I was charged twice'. A duplicate is the same account, merchant and amount on the same day.

Return account_id, merchant, amount, txn_date and copies for every charge that appears more than once. Sort by txn_date.

Starting Postgres in your browser…

Checking your access…