I have a table that has a bunch of sales orders. The table contains StoreIDs, OrderIDs, Total Payments and OrderDate. I have a query which I have included below that gives me a list of all the stores with the total payments (across all orders of that store) for every store. Now I want to be able to create a report that displays this information per month. However if I include the OrderDate field and try and group by OrderDate and then Store ID, I get multiple rows for the same store ID for each month for each of the store IDs because each store may have had multiple orders placed in each month. How can i get a result set that has all the storeIDs appearing only once (for each month) with the total payments made for each store.
SELECT StoreId, SUM(TotalPayments) AS [Total Payments]
GROUP BY StoreId
ORDER BY StoreId
I have tried this
SELECT OrderID, StoreId, SUM(TotalCharges) AS [Total Charges], SUM(TotalPayments) AS [Total Payments]
GROUP BY OrderID,StoreId
ORDER BY OrderID, StoreId