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.
copies descending, then vendor_id, then invoice_numberinvoices| amount | loaded_at | vendor_id | invoice_id | invoice_number |
|---|---|---|---|---|
| 250 | 2024-05-02 01:10:00 | 7 | 1 | INV-1001 |
| 250 | 2024-05-03 01:10:00 | 7 | 2 | INV-1001 |
| 99.5 | 2024-05-02 02:00:00 | 8 | 3 | INV-2001 |
| vendor_id | invoice_number | amount | copies | first_loaded_at |
|---|---|---|---|---|
| 7 | INV-1001 | 250 | 2 | 2024-05-02 01:10:00 |
invoices| amount | loaded_at | vendor_id | invoice_id | invoice_number |
|---|---|---|---|---|
| 10 | 2024-05-01 00:00:00 | 7 | 1 | INV-1 |
| 10 | 2024-05-01 00:00:00 | 7 | 2 | INV-2 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.