关系数据库连接仅显示一行

时间:2015-04-16 01:32:43

标签: mysql

我有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返回所有行?

1 个答案:

答案 0 :(得分:2)

您的陈述末尾似乎缺少"GROUP BY B.BranchNumber, B.BuildingName"条款