Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total sales per month

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 
like image 641
Costa Avatar asked May 12 '11 21:05

Costa


2 Answers

  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)
like image 165
mellamokb Avatar answered Oct 08 '22 13:10

mellamokb


SELECT CONVERT(CHAR(7), SmallDateTime, 120) as Year_Month,
       SUM(Price)
    FROM Sales
    GROUP BY CONVERT(CHAR(7), SmallDateTime, 120) 
    ORDER BY Year_Month
like image 34
Joe Stefanelli Avatar answered Oct 08 '22 11:10

Joe Stefanelli