2013-03-21 83 views
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; 

这是我code..when执行我在LEFT JOIN说,语法是wrong.Anybody帮助,请...我已经通了语法教程,但得到错误结果空手而归。谢谢。合成结果与左连接加入

+0

这是我errror ...你有一个错误的SQL语法;检查与您的MySQL服务器版本相对应的手册,以便在'LEFT JOIN (SELECT distinct c.sid_ident as name,c.fix_ident from corept.std_sid_'at line 2 – user2037445 2013-03-21 07:15:32

+0

'')处使用正确的语法,为什么不使用union ? – xurca 2013-03-21 07:16:44

+0

我需要找到数据差异 – user2037445 2013-03-21 07:18:30

回答

4

WHERE子句移到查询的末尾。另外,WHERE条款中的那个列trans是什么?它从哪里来的?如果它是一个字符串,那么,把它放在引号中。

应该这样写:

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 ; 
+0

+1对于敏锐的眼睛。**'name' ** if varchar should'in quoted'。 我认为它也可能产生错误。 – Luv 2013-03-21 07:19:20

+0

@Luv谢谢 - 我不确定,我只是复制它的问题,我认为问题是'name!= trans'','trans'应该引用。 – 2013-03-21 07:22:35

+0

no..trans是skyplan_deploy.deploy_sids表中的字段 – user2037445 2013-03-21 08:20:07