2017-02-24 106 views
1

我試圖執行以下查詢,它給出了一個語法錯誤,有人指出我的問題是?使用多個連接時出錯

select count(*) from (((
select * from testlink1915.TL_tcversions where execution_type = 2 and id = 66134) c 
JOIN (select * from testlink1915.TL_nodes_heirachy) d 
    ON id = testlink1915.TL_nodes_heirachy.parent_id) a 
JOIN (select * FROM testlink1915.TL_req_coverage where req_id = 67635) b 
    ON a.id = b.testcase_id); 

僅當我添加以下段時纔出現錯誤。

c JOIN (select * from testlink1915.TL_nodes_heirachy) d 
    ON id = testlink1915.TL_nodes_heirachy.parent_id 

錯誤

錯誤代碼:1064您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'JOIN附近使用正確的語法(select * FROM testlink1915.TL_req_coverage where req_id = 67635)b ON a。'在1號線

回答

1

用途:用於

c.id = d.parent_id 

代替

id = testlink1915.TL_nodes_heirachy.parent_id 

試試這個:

select count(*) 
from (
    select * 
    from (
     select * 
     from (
      select * 
      from testlink1915.TL_tcversions 
      where execution_type = 2 
       and id = 66134 
      ) c join (
      select * 
      from testlink1915.TL_nodes_heirachy 
      ) d on c.id = d.parent_id 
     ) a join (
     select * 
     from testlink1915.TL_req_coverage 
     where req_id = 67635 
     ) b on a.id = b.testcase_id 
    ) t; 

請注意,我用*無處不在。將其替換爲您需要的列。

+0

感謝您的答覆。但我仍然得到相同的錯誤,當我刪除「c加入( 選擇* 從testlink1915.TL_nodes_heirachy )d上c.id = d.parent_id」它開始工作。我在這裏錯過的任何東西? – ycr

+0

U需要爲roor select語句添加一個別名。然後它的工作,非常感謝。 – ycr

+1

已更新。如果有幫助,請考慮標記答案。 – GurV

0
Try below query : 

select count(*) from 
(
    (
    select * from testlink1915.TL_tcversions 
    JOIN testlink1915.TL_nodes_heirachy ON id = 
    testlink1915.TL_nodes_heirachy.parent_id where execution_type = 2 and id 
    = 66134 
    ) a 
JOIN 
    (
    select * FROM testlink1915.TL_req_coverage where req_id = 67635 
    ) ON a.id = b.testcase_id 
) ; 
1

請試試這個

select count(1) from 
    (
    select * from (
    select * from testlink1915.TL_tcversions where execution_type = 2 and id = 66134) c 
    JOIN 
    (select * from testlink1915.TL_nodes_heirachy) d on a.id=d.parent_id 
    join 
    (select * FROM testlink1915.TL_req_coverage where req_id = 67635) a ON a.id = b.testcase_id 

) as E join (select * from testlink1915.TL_nodes_heirachy) F ON E.id = F.parent_id