我有两张桌子,一张是产品清单,另一张是收银台。
我写过这个问题:
SELECT tblComponents.Name, tblComponents.Tax,
SUM(CONVERT(int,ProductCheckout.ItemQuantity)) as Quantity
FROM tblComponents
INNER JOIN ProductCheckout
ON tblComponents.ID=ProductCheckout.ItemID where tblComponents.Tax <> 0
Group BY tblComponents.Name, ProductCheckout.ItemQuantity, tblComponents.Tax;
我希望得到订购商品的总数/数量。
目前显示
OrderName 2.00 1
OrderName 2.00 2
我希望它显示:
OrderName 4 3
我希望获得所有产品名称的清单,以及所订税额和数量的总和。
我不确定这个查询有什么问题,但我需要指出正确的方向。
答案 0 :(得分:2)
我认为您不应该在ProductCheckout.ItemQuantity
子句中加入tblComponents.Tax
或Group By
,而应该对tblComponents.Tax
列进行总结。类似的东西:
SELECT tblComponents.Name, SUM(tblComponents.Tax),
SUM(CONVERT(int,ProductCheckout.ItemQuantity)) as Quantity
FROM tblComponents
INNER JOIN ProductCheckout
ON tblComponents.ID=ProductCheckout.ItemID where tblComponents.Tax <> 0
Group BY tblComponents.Name;