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
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: CommandType对数据库操作的影响