SELECT name,trans FROM skyplan_deploy.deploy_stars d WHERE d.apt='KOPF' AND d.name!=d.trans
LEFT OUTER JOIN
(SELECT distinct c.star_ident,c.fix_ident from corept.std_star_leg c
INNER JOIN
(SELECT star_ident,transition_ident,max(sequence_num) seq,route_type
FROM corept.std_star_leg
WHERE data_supplier='J' AND airport_ident='KOPF'
group by star_ident,transition_ident)b
ON c.sequence_num=b.seq and c.star_ident=b.star_ident and c.transition_ident=b.transition_ident) as y
ON c.sid_ident=x.name AND c.fix_ident=x.trans
where y.data_supplier='J' and y.airport_ident='KOPF' and y.name is null;
执行上述查询时,我收到以下语法错误。
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'LEFT OUTER JOIN
(从corept.std_sta'中选择不同的c.star_ident,c.fix_ident 3
我使用了左连接,这样我就能从上面的两个查询中获得数据差异。我甚至将where条件放在最后。
答案 0 :(得分:4)
找到错误的一个好方法是将其分解并分别尝试组件。例如,尝试:
SELECT star_ident,transition_ident,max(sequence_num) seq,route_type
FROM corept.std_star_leg
WHERE data_supplier='J' AND airport_ident='KOPF'
group by star_ident,transition_ident
查看该子查询是否存在任何问题。
当查询没有语法错误但没有产生预期结果时,将查询分解为可理解的部分通常是调试它的最快方法。
答案 1 :(得分:3)
您的错误原因是无效使用LEFT JOIN
。基本SELECT
语法如下,
SELECT ...
FROM ... JOIN...
WHERE ...
GROUP BY...
ORDER BY ...
您在LEFT JOIN
子句之后使用WHERE
会导致语法错误。