【问题标题】:Match multiple rows one table with multiple columns of another table mysql将一张表的多行与另一张表的多列匹配mysql
【发布时间】:2017-02-17 10:29:44
【问题描述】:

我有两张桌子

第一个表:联系人列:

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 进行检查。

有什么建议可以解决这个问题吗?

【问题讨论】:

  • 列名双引号?你确定吗??
  • 真的有像Contacts (Boost Media Group)这样的表名吗
  • 还有像"Zoho Projects ID 1"这样的列名
  • 请删除双引号
  • 问题是如何将时间表表的行与联系人表的多列匹配。目前我可以匹配一列联系表。我也会删除引号。

标签: mysql zoho


【解决方案1】:

如果我错了,请纠正我。我猜当任何条件(Zoho Projects ID 3 或 Zoho Projects ID 2 或 Zoho Projects 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"

【讨论】:

  • @Gurpreet 下次当您需要有关您正在使用的产品的帮助时,请随时联系支持团队。
【解决方案2】:

试试这个查询

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

【讨论】:

    猜你喜欢
    • 2012-01-23
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    相关资源
    最近更新 更多