2017-02-17 83 views
0

我有2個表匹配多行一個表與另一個表的多個列的MySQL

第一個表:聯繫人列:

Customer ID,Project ID1,Project ID2,Project ID3 

這樣一個聯繫方式將具有一行。

第二表:時間表列

Project ID, Name, Owner, Hours 

一個接觸可以有多個項。

我想匹配時間表中的項目ID到3列聯繫人表。

我正在使用以下查詢。

SELECT "Customer ID","Project ID","Project Name","Owner", 
     "Hours","Approval Status","Status","Project Manager", 
     "Sales Person","Account Manager","Discount %","Hourly Rate", 
     "Monthly Budget","Total Budget" 
FROM "Timesheets" 
    LEFT JOIN "Contacts (Boost Media Group)" 
     ON "Timesheets"."Project ID" = "Contacts (Boost Media Group)"."Zoho Projects ID 1"; 

但它沒有返回所需的結果,因爲我無法使用聯繫人表的項目ID2,項目ID3來檢查它。

任何建議如何解決這個問題?

+0

雙引號maches?你確定?? – RiggsFolly

+1

你真的**有像'Contacts(Boost Media Group)' – RiggsFolly

+1

這樣的表名和'Zoho Projects ID 1'這樣的列名'' – RiggsFolly

回答

1

糾正我,如果我錯了。我想你希望他們在任何條件(百會項目編號3或Zoho項目ID 2或Zoho項目ID 1)與「時間表」,「項目ID」,圍繞列名

SELECT "Customer ID","Project ID","Project Name","Owner", 
     "Hours","Approval Status","Status","Project Manager", 
     "Sales Person","Account Manager","Discount %","Hourly Rate", 
     "Monthly Budget","Total Budget" 
FROM "Timesheets" 
    LEFT JOIN "Contacts (Boost Media Group)" 
     ON "Timesheets"."Project ID" = "Contacts (Boost Media Group)"."Zoho Projects ID 1" 
or "Timesheets"."Project ID" = "Contacts (Boost Media Group)"."Zoho Projects ID 2" 
or "Timesheets"."Project ID" = "Contacts (Boost Media Group)"."Zoho Projects ID 3" 
+0

非常感謝。它真的適合我。 –

+0

@Gurpreet下次您需要使用您所使用的產品的幫助時,請不要猶豫與支持團隊聯繫。 –

0

嘗試此查詢

SELECT `(Boost Media Group)`.`Customer ID`,`tyshet`.`Project ID`,`tyshet`.`Project Name`,`tyshet`.`Owner`, 
     `tyshet`.`Hours`,`tyshet`.`Approval Status`,`tyshet`.`Status`,`tyshet`.`Project Manager`, 
     `tyshet`.`Sales Person`,`tyshet`.`Account Manager`,`tyshet`.`Discount %`,`tyshet`.`Hourly Rate`, 
     `tyshet`.`Monthly Budget`,`tyshet`.`Total Budget` 
FROM Timesheets as `tyshet` 
    LEFT JOIN Contacts as `(Boost Media Group)` 
     ON `tyshet`.`Project ID` = `(Boost Media Group)`.`Zoho Projects ID 1`; 
相關問題