I have a table of customer purchases, with the price paid and tax paid for the item. I have a query which will group the number of purchases based on the Month and year, and it works great. See illustration #1 of the result which works great.
However what I need to do is to also display the total of
the purchases per month, plus the total of the taxes paid on all of the purchases made per month. Also I would like the grand total for each month.
I tried doing this using the SUM command but it did not work. Look at Illustration #2 of the desired output which I need. Can someone show me how
to modify my query to display the result shown in Illustration #2. The Grand totals line would also be nice, however my first priority is
to get the monthly totals, TotalPurchasePrice and TotalTaxes. Can someone please help me out with the query?
Table
ID
CustName
PurchaseDate
PurchasePrice
Tax
select YEAR(PurchaseDate) AS Year, MONTH(PurchaseDate) AS Month, COUNT(*) FROM Customers Group By YEAR(PurchaseDate),MONTH(PurchaseDate)
ID Year Month Purchases
1 2016 7 3 -- 3 customer purchases occurred during the month of July
2 2016 8 5
3 2016 9 10
Illustration #2
ID Year Month Purchases TotalPurchasePrice TotalTaxes
1 2016 7 3 234.44 55.00
2 2016 8 5 888.33 77.00
3 2016 9 10 987.44 45.00
GrandTotals 18 2110.21 177.00
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
This award recognizes a member of Experts Exchange who has made outstanding contributions to the community within their first year as an expert. The Rookie of the Year is awarded to a new expert who has the highest number of quality contributions.