以下是我的查询:
SELECT DATENAME(MONTH,timeofpurchase) as 'Month',
COUNT(*) 'Transactions', SUM(totalprice) as 'Total Sales'
FROM transactions
GROUP BY DATENAME(MONTH,timeofpurchase)
ORDER BY DATENAME(MONTH,timeofpurchase) DESC
答案 0 :(得分:0)
查看更多信息:ORDER BY FIELD
这应该有所帮助:
SELECT DATENAME(MONTH,timeofpurchase) as 'Month',
COUNT(*) 'Transactions', SUM(totalprice) as 'Total Sales'
FROM transactions
GROUP BY DATENAME(MONTH,timeofpurchase)
ORDER BY FIELD(MONTH,'January','February','March','April',...,'December') DESC;
答案 1 :(得分:0)
我能想到的一个简单的解决方法是构建另一个存储1和1月,2月和2月的表,依此类推。然后按数字列进行连接和排序。