我有这个 MySQL 查询,它返回某个 Product_ID 的销售细分。
我想扩展此查询以包含多个 Product_ID。
继承人我有什么给我 1 Product_ID:
SELECT
o.Customer_ID, o.CompanyName, cg.Category, o.Order_ID,
SUM(old.LineTotal) as TOTAL,
SUM(old.qty) as PID,
COUNT(o.Order_ID) as OIDs
FROM Orders o
LEFT JOIN Order_LineDetails old ON old.Order_ID = o.Order_ID
LEFT JOIN CustomerDetails cd ON o.Customer_ID = cd.Customer_ID
LEFT JOIN _CustomerCategory cg ON cg.Category_ID = cd.Category_ID
WHERE o.IsPENDING = 0
AND o.OrderPlaceServerTime >= '2012-1-1'
AND o.OrderPlaceServerTime <= '2012-9-1'
AND o.IsVOID = 0
AND old.Product_ID = '56789'
GROUP BY o.Customer_ID
ORDER BY TOTAL DESC
LIMIT 10
我正在尝试添加一些东西来做超过 1 个 Product_ID 并获取它们的 SUM。
这是我正在考虑的想法,但显然这不起作用。
(CASE WHEN old.Product_ID = '56789'
SUM(old.LineTotal) as TOTAL_56789,
SUM(old.qty) as PID_56789)
这将根据我追求的产品数量重复。
希望这是有道理的。
有什么建议么?
编辑::
这是我想要返回的示例。