我认为你应该order by
在最后使用条款
SELECT { fn MONTHNAME(OrderDate) } AS MonthName, YEAR(OrderDate) AS Year, SUM(TotalValue) AS Profits
FROM [Order]
WHERE (YEAR(OrderDate) = @year)
GROUP BY { fn MONTHNAME(OrderDate) }, YEAR(OrderDate)
ORDER BY { fn MONTH(OrderDate) }, YEAR(OrderDate)
或者
你可以这样做
SELECT CASE { fn MONTH(OrderDate) }
when 0 then 'JAN'
when 1 then 'FEB'
when 2 then 'MAR'
when 3 then 'APR'
when 4 then 'MAY'
when 5 then 'JUN'
when 6 then 'JUL'
when 7 then 'AUG'
when 8 then 'SEP'
when 9 then 'OCT'
when 10 then 'NOV'
when 11 then 'DEC'
END
AS MonthName, YEAR(OrderDate) AS Year, SUM(TotalValue) AS Profits
FROM [Order]
WHERE (YEAR(OrderDate) = @year)
GROUP BY { fn MONTH(OrderDate) }, YEAR(OrderDate)
ORDER BY { fn MONTH(OrderDate) }, YEAR(OrderDate)