Order By month and year in sql with sum

前端 未结 7 2205
说谎
说谎 2020-12-29 08:58

I have a stored procedure and the select statement is:

SELECT     { fn MONTHNAME(OrderDate) } AS MonthName, YEAR(OrderDate) AS Year, SUM(TotalValue) AS Profi         


        
7条回答
  •  盖世英雄少女心
    2020-12-29 09:23

    If you want to order as Jan, Feb, March use

    SELECT 
      month(OrderDate) MonthName, 
      year(OrderDate) Year, 
      sum(TotalValue) Profits
    FROM         
      [Order]
    WHERE     
      month(OrderDate) = @year
    ORDER BY 
      year(OrderDate), 
      month(OrderDate)
    GROUP BY 
      year(OrderDate),
      month(OrderDate)
    

提交回复
热议问题