SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
WITH tmp AS ( SELECT airport_name->>'en' AS departure_airport, arrival_airport AS arrival_airports FROM airports_data ad JOIN flights f ON ad.airport_code = f.departure_airport ) SELECT departure_airport, json_agg(DISTINCT ad2.airport_name->>'en' ORDER BY ad2.airport_name->>'en') AS arrival_airports FROM tmp JOIN airports_data ad2 ON airport_code = arrival_airports GROUP BY departure_airport ORDER BY departure_airport

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear