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.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

leg_sourceparcel_codehandler_namedistance_km
courierPCL-1001Ivan Petrov3.5
truckPCL-1001Sergey Lomov210
courierPCL-1002Olga Sokolova7.2
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid