我有SQL查询:
SELECT B.branchNumber, B.buildingName, SUM(CASE WHEN PI.offerPrice > 0 THEN PI.offerPrice * PI.quantity ELSE price * PI.quantity END) AS total
FROM `purchase`
INNER JOIN `product` on purchase.productCode = product.productCode
INNER JOIN `branch` B on purchase.branchNumber = B.branchNumber
INNER JOIN `purchase info` PI on purchase.productCode = PI.productCode AND purchase.purchaseID = PI.purchaseID
仅返回一个total
由于INNER JOIN
仅显示与total
匹配的列。当我删除:
SUM(CASE WHEN PI.offerPrice > 0 THEN PI.offerPrice * PI.quantity ELSE price * PI.quantity END) AS total
它返回几行。如何通过total
s返回所有行?
答案 0 :(得分:2)
您的陈述末尾似乎缺少"GROUP BY B.BranchNumber, B.BuildingName"
条款