2013-03-21 116 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