【问题标题】:Joining two tables without a common column but using another table connected to both连接没有公共列但使用连接到两者的另一个表的两个表
【发布时间】:2019-08-26 15:16:30
【问题描述】:

我在Mysql中有三个表

  • 表 A-> uid, itemType, balance,orderType
  • 表B-> orderId, itemType, 数量
  • 表 C-> uid,orderId

我需要为每个 uid:orderIdcombination 获取特定类型项目的 (balance-qty)。如果表 A 和表 B 没有要加入的公共列,我该如何连接它们。但是它们都连接到表C。

【问题讨论】:

标签: mysql


【解决方案1】:

三个表之间的连接:

select a.uid, a.balance, b.qty
from tablea a 
inner join tablec c on c.uid = a.uid
inner join tableb b on b.orderid = c.orderid
where a.itemtype = ?

如果需要,您可以添加更多列。

【讨论】:

    猜你喜欢
    • 2021-09-20
    • 2015-11-11
    • 1970-01-01
    • 2013-11-04
    • 2022-08-19
    • 2023-03-19
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    相关资源
    最近更新 更多