SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select s.air_1 as departure_airport, s.air_2 as arrival_airport from (select LEAST(airport_1,airport_2) as air_1, GREATEST(airport_2,airport_1) as air_2 from (select airport_name->>'en' as airport_1 from airports_data) a cross join (select airport_name->>'en' as airport_2 from airports_data) ad where airport_1<>airport_2 and airport_2<>'Anapa Vityazevo Airport' group by LEAST(airport_1,airport_2), GREATEST(airport_2,airport_1)) s where NOT Exists (select a.airport_name->>'en' as departure_airport, ad.airport_name->>'en' as arrival_airport from (select distinct f.departure_airport, f.arrival_airport from flights f) as f join airports_data a on a.airport_code = f.departure_airport join airports_data ad on ad.airport_code = f.arrival_airport where a.airport_name->>'en' = s.air_1 and ad.airport_name->>'en' = s.air_2) group by s.air_1,s.air_2 order by 1,2

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear