下面我有一个 T-SQL 查询,它带回购买商品的数量、折扣和总数——按购买的月/年分组。如何更新查询以返回总计行,我可以将总计列中的金额相加?能够将所有行加起来会很好,但我的主要项目是我需要能够获得总计。谢谢。
Select DATENAME(month, [OrderDate]) + ' ' + CAST(YEAR(OrderDate) AS CHAR(4))
AS [Month],
SUM(Amount) AS [Amount],
SUM(Discount1) AS [Discount 1],
SUM(Discount2) AS [Discount 2],
SUM(Amount - Discount1 - Discount2) AS [Total]
From
Orders
JOIN Customer on orders.cust_ky=customer.cust_ky
GROUP BY DATENAME(month, [OrderDate]) + ' ' + CAST(YEAR(OrderDate) AS CHAR(4))
ORDER BY MAX(OrderDate)