mysql中對聚合函數求和的方法
在mysql中使用sum對聚合函數求和,sql語句如下:
SELECT
p.Id Id,
p.ImgUrl ImgUrl,
p.Title Title,
p.ReferOutPrice ReferOutPrice,
e.`Status`,
SUM(IF(e.`Status`=1 OR e.`Status`=2, ed.Number,0))
FROM
Product p
LEFT JOIN EBOrdersDetails ed ON p.id = ed.ProductId
LEFT JOIN EBOrders e ON ed.PurchaseNo = e.PurchaseNo
WHERE
p.StoreId = 143
AND p.`Status` >-1
GROUP BY p.Id