我学习了比通常更高级的SQL,但我在这里有一点卡住了。
查询是获取航空公司从用户输入的起点飞往的所有机场(目的地)。
SELECT DISTINCT a.airline_name, GROUP_CONCAT(ap.city) AS groupedDestinations
FROM routes AS r
LEFT JOIN airlines AS a
ON r.airline = a.airline_iata
LEFT JOIN airports AS ap
ON r.destination = ap.airport_iata
WHERE r.origin = ? AND a.active="Y" AND r.codeshare != "Y"
GROUP BY a.airline_name ASC
结果应该是:
Airline Name | city1, city2
相反,这是:
Airline Name | city1, city2, city1, city2
我花了几个小时才达到这一点,所以我会感激任何建议、抨击或答案 :)
谢谢。