Duplicate Parcel Registrations
Duplicate Parcel Registrations
You are the data quality analyst for a last-mile delivery platform. Warehouses upload parcel registrations in batches, and retrying a file can create several rows for the same physical parcel. Before carrier compensation is calculated, the billing team needs a duplicate audit so one parcel is not charged more than once.
A registration's business key is the pair carrier_code + tracking_number. Consider only rows where both key components are present: the value is not NULL and is not empty after trimming leading and trailing spaces. Find business keys that occur more than once, count all rows in each duplicate group, and identify the first and last registration times.
Business-key comparison is exact and case-sensitive. Count every row in a matching group, even when all non-key fields are identical.
Return columns:
- carrier_code — carrier code, text;
- tracking_number — tracking number, text;
- duplicate_count — number of rows with this business key, integer;
- first_registered_at — earliest registration time, timestamp with time zone;
- last_registered_at — latest registration time, timestamp with time zone.
Sort by duplicate_count descending, then by carrier_code and tracking_number ascending. No rounding is required. Rows with an incomplete business key must be excluded. Resolve count ties with the stated secondary sort fields.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.
| carrier_code | tracking_number | duplicate_count | first_registered_at | last_registered_at |
|---|---|---|---|---|
| FEDEX | FX3002 | 3 | 2026-05-01T11:20:00+00:00 | 2026-05-01T11:45:00+00:00 |
| DHL | TRK1001 | 2 | 2026-05-01T09:00:00+00:00 | 2026-05-01T09:05:00+00:00 |
| UPS | UP2001 | 2 | 2026-05-01T10:10:00+00:00 | 2026-05-01T11:00:00+00:00 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in