Find exact duplicate rows in a raw order load
The task
The pipeline sometimes loads the same copy of an order twice. An exact repeat has the same order_id, customer_id, order_total, currency, order_status and updated_at as another row. Only loaded_at is different. Two rows that share order_id and updated_at but differ in any other column are not exact repeats.
List every copy of an order that appears more than once. Return order_id, updated_at and copies (how many rows are exact repeats of each other). Sort by order_id, then updated_at.
Expected output
order_idupdated_atcopies- Sorted by order_id ascending, then updated_at ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Analytics warehouse · click a name to insert it
stg_orders669 rows in the sample
Raw order rows as loaded from the source. The same order can arrive several times: each change in the source sends a new copy, and some loads repeat a copy exactly.
| int | Order id from the source. | |
| int | Customer id. | |
| numeric(10,2) | Order total in the order currency. | |
| text | USD, EUR or GBP. | |
| text | placed, shipped, delivered or cancelled. | |
| timestamp | When the source last changed this order (UTC). | |
| timestamp | When our pipeline loaded this copy (UTC). |
dim_customers_history120 rows in the sample
Type 2 history: one row per version of a customer. A version is valid from valid_from up to, not including, valid_to. Key: customer_id, valid_from.
| int | Customer id. | |
| text | Name. | |
| text | bronze, silver or gold. | |
| text | EMEA, AMER or APAC. | |
| timestamp | Start of this version (UTC). | |
| timestamp | End of this version (not included). NULL for the current version. |
fx_rates254 rows in the sample
Closing exchange rates on business days only (no weekend rows). Key: rate_date, currency.
| date | Business day. | |
| text | EUR or GBP. | |
| numeric(12,6) | US dollars for one unit of the currency. |
inventory_snapshots336 rows in the sample
Stock on hand per product at the end of each day. A product missing from a day had no snapshot taken. Key: snapshot_date, sku.
| date | Day of the snapshot. | |
| text | Product code. | |
| int | Units in stock. |
Related questions
- Orders by current status from a raw loadmedium
- Current order copy when two copies share a timestamphard
- How many rows would deduplication remove?easy
- Salary in effect on a date for each employeemedium
- Customers with several accounts under one emaileasy
- Emails shared by accounts that disagree on countrymedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL