以下に、日付に基づいて結果を返す T-SQL クエリがあります。
SELECT
SUM(CASE WHEN date ='2012-10-31' then Amount ELSE 0 END) AS [Amount],
SUM(CASE WHEN date ='2012-10-31' then Discount1 ELSE 0 END) AS [Discount 1],
SUM(CASE WHEN date ='2012-10-31' then Discount2 ELSE 0 END) AS [Discount 2]
SUM(CASE WHEN date ='2012-10-31' then Amount - Discount1 - Discount2 ELSE 0 END) AS
[Total Amount]
FROM
Orders
現在の結果:
Amount Discount1 Discount2 Total
--------------------------------------
100.00 5.00 5.00 90.00
これを実行して、月ごとに表示/グループ化したいと思います。何か案は?
Amount Discount1 Discount2 Total
-------------------------------------------
October 100.00 5.00 5.00 90.00
November 100.00 10.00 5.00 85.00
December 200.00 20.00 10.00 170.00