通过下表详细说明,我想列出订单ID和每个订单的总成本。
Product (ProductID,ProductDescription, QtyInStock, ReOrderLevel, CostPrice, SellPrice)
Order(OrderNum, OrderDate, DeliveryDate)
OrderDetails (OrderDetailID, OrderNum, ProductID, Quantity)
我的捅,我有
SELECT OrderNumber, sum(SellPrice * Quantity) AS TotalCost
FROM OrderDetail
INNER JOIN Product
ON Product.ProductID = OrderDetail.ProductID
如何显示每个订单编号的总和结果?
答案 0 :(得分:0)
您应该使用SELECT OrderNumber, sum(SellPrice * Quantity) AS TotalCost
FROM OrderDetail
INNER JOIN Product
ON Product.ProductID = OrderDetail.ProductID
group by OrderNumber
对结果进行分组。现在你得到所有的总和,并在每一行显示它。
此代码将提供您期望的结果:
{{1}}