← Problems15. Find duplicate invoicesEasySQL
00:00 / 20:00

Find duplicate invoices

Easy·Acceptance 13%·Asked at Walmart, Deloitte

An upstream loader retried without idempotency, so some invoices were inserted more than once. Two rows are duplicates when vendor_id, invoice_number and amount all match. Return one row per duplicate group with the number of copies and the earliest loaded_at.

Input schema

invoices invoice_id bigint vendor_id bigint invoice_number string amount numeric loaded_at timestamp

Example

vendor_id invoice_number amount copies first_loaded_at 7 INV-1001 250.00 3 2024-05-02 01:10 9 INV-2222 1400.00 2 2024-05-03 02:00

Constraints

  • Groups with a single row are not duplicates and must not appear
  • Order by copies descending, then vendor_id, then invoice_number
  • Up to 40,000,000 rows

Topics

deduplicationaggregation

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.sql
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8 · ⌘↵ run, ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.