我試圖寫一個查詢,確定哪些城市我不能直接從一個城市飛往倫敦。鑑於模式:試圖找到所有沒有直飛城市的城市(PostgreSQL)
城市:
| c_id | city_name |
航班:
| f_id | departure_city_id | destination_city_id |
目前我的查詢返回相反的,也就是說,它返回其中有來自倫敦
直達航班的城市SELECT c2.city_name as "City"
FROM flights AS f
JOIN cities AS c2 ON f.destination_city_id != c2.c_id
JOIN cities AS c ON c.c_id = c.c_id
WHERE c.city_name = 'London'
AND c.c_id != c2.c_id
AND f.departure_city_id = c.c_id;
我原以爲這會很容易改變它得到我想要的。 我以爲改變第三行
JOIN cities AS c2 ON f.destination_city_id = c2.c_id
會做的伎倆,但事實並非如此。任何幫助?