我有这三张桌子......
currency (Currency),
purchasingqty (PurchasingID, Rate, Qty)
salesqty (SalesID, Rate, Qty)
我只需要在一个查询中从这3个表中检索记录,而不需要重复。但是这个会返回重复项。
SELECT
currency.Currency,
purchASingqty.PurchASingID,
IFNULL(purchASingqty.Rate,0) AS Pur_Rate,
SUM(IFNULL(purchASingqty.Qty,0)) AS Pur_Qty,
salesqty.SalesID,
IFNULL(salesqty.Rate,0) AS Sales_Rate,
SUM(IFNULL(salesqty.Qty,0)) AS Sales_Qty
FROM currency
LEFT JOIN salesqty ON currency.Currency = salesqty.Currency
LEFT JOIN purchASingqty ON currency.Currency = purchASingqty.Currency
GROUP BY
purchASingqty.PurchASingID,
salesqty.SalesID