4
SELECT name,trans FROM skyplan_deploy.deploy_sids d WHERE apt='KBOS' AND name != trans  
LEFT JOIN  
(SELECT distinct c.sid_ident as name,c.fix_ident from corept.std_sid_leg as c  
   INNER JOIN  
        (SELECT sid_ident,transition_ident,max(sequence_num) seq,route_type  
         FROM corept.std_sid_leg  
         WHERE data_supplier='J' AND airport_ident='KBOS'  
         GROUP BY sid_ident,transition_ident)b  
         ON c.sequence_num=b.seq and c.sid_ident=b.sid_ident and        c.transition_ident=b.transition_ident  
         WHERE c.data_supplier='J' and c.airport_ident='KBOS')right_tbl  
ON d.name=right_tbl.sid_ident;

这是我的代码..执行时我在左连接时遇到错误,说语法错误。请大家帮忙...我已经完成了语法教程,但结果却是空手而归。谢谢。

4

1 回答 1

4

WHERE子句移动到查询的末尾。另外,子句中的那一列是什么transWHERE它从哪里来的?如果它是字符串文字,则将其放在引号中。

应该这样写:

SELECT 
  name,
  trans 
FROM skyplan_deploy.deploy_sids d 
LEFT JOIN
(
   SELECT distinct c.sid_ident as name, c.fix_ident 
   from corept.std_sid_leg as c
   INNER JOIN
   (
      SELECT sid_ident, transition_ident, max(sequence_num) seq, route_type
      FROM corept.std_sid_leg
      WHERE data_supplier='J' AND airport_ident='KBOS'
      GROUP BY sid_ident,transition_ident
   ) b ON c.sequence_num=b.seq 
       and c.sid_ident = b.sid_ident 
       and c.transition_ident = b.transition_ident
    WHERE c.data_supplier='J' and c.airport_ident='KBOS'
) AS right_tbl  ON d.name = right_tbl.sid_ident
WHERE apt = 'KBOS'
  AND right_tbl.sid_ident IS NULL ;
于 2013-03-21T07:16:11.613 回答