[英]Relational database join only showing one row
我有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的所有行?
您似乎在语句末尾缺少"GROUP BY B.BranchNumber, B.BuildingName"
子句
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.