One register for every delivery leg
One register for every delivery leg
You are an analyst at a delivery company. Parcels move around the city with couriers and between cities with trucks, and historically these two flows are written into separate tables. Before the month is closed, finance asks for a single end-to-end register of the legs worked: who carried what parcel and over what distance. For them every row is a separate billable fact, so identical records must not be collapsed: if a courier ran the same leg for the same parcel twice, they get paid twice.
Return columns:
- leg_source — where the record comes from: the text 'courier' for city legs and 'truck' for intercity legs;
- parcel_code — parcel code;
- handler_name — the courier's name for city legs or the driver's name for intercity legs;
- distance_km — leg distance in kilometres, exactly as stored, with no rounding.
Sorting: by parcel_code, then leg_source, then handler_name, then distance_km, all ascending. Do not remove duplicates: fully identical rows must appear in the result as many times as they occur in the source tables.
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.
| leg_source | parcel_code | handler_name | distance_km |
|---|---|---|---|
| courier | PCL-1001 | Ivan Petrov | 3.5 |
| truck | PCL-1001 | Sergey Lomov | 210 |
| courier | PCL-1002 | Olga Sokolova | 7.2 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in