If you have a table with SALES {Customer_ID, Price, SmallDateTime date}
. How do you report all sales per month?
SELECT Sum(Price) As Total Sales FROM SALES Group By What Having What
SELECT YEAR(date) as SalesYear,
MONTH(date) as SalesMonth,
SUM(Price) AS TotalSales
FROM Sales
GROUP BY YEAR(date), MONTH(date)
ORDER BY YEAR(date), MONTH(date)
SELECT CONVERT(CHAR(7), SmallDateTime, 120) as Year_Month,
SUM(Price)
FROM Sales
GROUP BY CONVERT(CHAR(7), SmallDateTime, 120)
ORDER BY Year_Month
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With