将一个 table 的多行与另一个 table mysql 的多列匹配

Match multiple rows one table with multiple columns of another table mysql

我有 2 table

第一个Table:联系专栏:

Customer ID,Project ID1,Project ID2,Project ID3

所以一个联系人将占一行。

第二Table:时间sheet列

Project ID, Name, Owner, Hours

一个联系人可以有多个条目。

我想将项目 ID 从时间 sheet table 匹配到 3 列联系人 table。

我正在使用以下查询。

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";

但它没有返回所需的结果,因为我无法使用联系人 table 的项目 ID2、项目 ID3 检查它。

有什么解决办法的建议吗?

试试这个查询

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`;

如果我错了请纠正我。我想当任何条件(Zoho Projects ID 3 或 Zoho Projects ID 2 或 Zoho Projects ID 1)与 "Timesheets"."Project 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"