我使用以下查询来获取OrderID:
SELECT OrderItem.ID
, ProductID
, OrderID
, Quantity
, P.Title
, P.CurrentPrice
, P.ID
, (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem
INNER JOIN Product AS P
ON OrderItem.ProductID = P.ID
如何获取每个OrderID的总金额(使用相同的OrderID添加所有总计)?
答案 0 :(得分:3)
您可以使用
选择和分组的选择表单select OrderID, sum(Total)
from (
SELECT
OrderItem.ID
, ProductID
, OrderID
, Quantity
, P.Title
,P.CurrentPrice
, P.ID
, (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem
INNER JOIN Product AS P ON OrderItem.ProductID = P.ID
) t
group by OrderId
答案 1 :(得分:0)
我只是SQL新手,但我认为这是解决方案。
SELECT OrderItem.ID, ProductID, OrderID, Sum(Quantity) AS Sum of Quantity, P.Title,P.CurrentPrice, P.ID, (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem INNER JOIN Product AS P ON OrderItem.ProductID = P.ID GROUP BY OrderID
希望这有助于。