我创建了两个临时表,并使用以下代码将它们连接在一起但遇到ERROR 1064 near 'LEFT JOIN'
。
(SELECT DISTINCT routes.route_short_name, MIN(stop_times.stop_sequence) AS first_stop, stops.stop_name AS first_stop_name
FROM trips
JOIN routes ON ...
JOIN stop_times ON ...
JOIN stops ON ...
JOIN calendar ON ...
GROUP BY stop_times.trip_id) first_table
LEFT JOIN
(SELECT DISTINCT routes.route_short_name, MAX(stop_times.stop_sequence) AS last_stop, stops.stop_name AS last_stop_name
FROM trips
JOIN routes ON ...
JOIN stop_times ON ...
JOIN stops ON ...
JOIN calendar ON ...
GROUP BY stop_times.trip_id) last_table
ON first_table.route_short_name = last_table.route_short_name;
期望的结果如下:
route_short_name, first_stop_name, last_stop_name
...
答案 0 :(得分:2)
您是否错过了实际的主要选择语句?
SELECT route_short_name, first_stop_name, last_stop_name FROM --this part is missing
(SELECT DISTINCT ...) first_table
LEFT JOIN
(SELECT DISTINCT ...) last_table
ON first_table.route_short_name = last_table.route_short_name;