我有2张桌子
第一张表:联系列:
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 :(得分:1)
如果我错了,请纠正我。当任何条件(Zoho Projects ID 3或Zoho Projects ID 2或Zoho Projects ID 1)与“Timesheets”匹配时,我猜你想要它们。“项目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"
答案 1 :(得分: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`;