You're a data quality analyst at a last-mile delivery platform. Warehouses upload parcel registrations in batches, and resubmitting a file sometimes creates multiple rows for the same parcel. Before calculating carrier payments, find these groups so a single physical parcel is not billed more than once.
A registration's business key is the pair carrier_code + tracking_number. Include only rows where both parts of the business key are present: neither value is NULL, and neither is an empty string after leading and trailing spaces are removed. Find business keys that occur more than once, count all rows in each group, and find the earliest and latest registration times.
Compare business key values exactly, including letter case. Count every row in each matching group, even if the other fields are identical.
Return these columns:
- carrier_code — carrier code, text;
- tracking_number — parcel 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 the result by duplicate_count in descending order, breaking ties by carrier_code and then tracking_number in ascending order. No rounding is needed, and rows with incomplete business keys must not appear.
carrier_codetracking_numberduplicate_countfirst_registered_atlast_registered_atSign in to see submission history
Sign inSign in to use AI Mentor
Sign in