如何将这些表合并成一个表,以便我可以找出哪个客户的订单数量最高?
表a |订单编号 |客户 ID | | -------- | -------------- | | 123| 999| | 456| 888|
表b |订单编号 |订单数量 | | -------- | -------------- | | 123| 178| | 456| 265|
表c |客户 ID |客户名称 | | -------- | -------------- | | 888|鲍勃| | 999|丹尼尔|
预期结果: |客户名称 |订单数量 | | -------- | -------------- | |鲍勃| 265| |丹尼尔| 178|
这是我的尝试:
select table b. orderquantity, table c. customername
from table b.
left join table a on table a.orderid = table b. orderid
left join table c on table c.customerid = table a. customerid
SELECT b.orderquantity, c.customername
FROM b
LEFT JOIN a ON a.orderid = b.orderid
LEFT JOIN c ON c.customerid = a.customerid
WHERE b.orderquantity = (SELECT MAX(orderquantity) FROM b);