The spaces that break routing

The spaces that break routing

You are a data engineer at a logistics operator. Handheld scanners in the warehouse add random spaces before and after the destination city name, so the sorting hub fails to match the destination against its directory. The operations team needs a report: the cleaned city name and exactly how many whitespace characters had to be removed per shipment — that tells them which scanners misbehave the most. Return columns: - shipment_id — shipment id (integer); - city_clean — city name with leading and trailing spaces removed (do not touch spaces between words); - chars_removed — how many characters were removed (length of the raw string minus length of the cleaned one, integer). Exclude shipments where the city is NULL. If a value consisted of spaces only, city_clean becomes an empty string — keep such rows in the report. Sorting: by chars_removed descending, ties by shipment_id ascending.

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.

shipment_idcity_cleanchars_removed
3Antwerp4
2Hamburg3
7Genoa3
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid