我想扭转我在这里的结果:
我知道我必须使用子查询,但它不能用作我的SQL代码:
SELECT MONTH(CaseTime) as 'Month',
COUNT(Case_ID) as 'Num'
FROM `Case`
GROUP BY MONTH(CaseTime)
ORDER BY CaseTime DESC LIMIT 6
MONTH(CaseTime)可能与别名冲突。
当前输出为:
Month / Num 5 / 1 4 / 1 3 / 1 2 / 1 1 / 18 12 / 13
期望输出应为:
Month 12 / 13 1 / 18 2 / 1 3 / 1 4 / 1 5 / 1
答案 0 :(得分:0)
这应该有效
SELECT MONTH(CaseTime) as 'Month',
COUNT(Case_ID) as 'Num'
FROM `Case`
GROUP BY MONTH(CaseTime)
ORDER BY 1 DESC LIMIT 6
注意:您可能需要YEAR
SELECT MONTH(CaseTime) as 'Month',
COUNT(Case_ID) as 'Num'
FROM `Case`
WHERE YEAR(CaseTime) = YEAR(CURDATE())
GROUP BY MONTH(CaseTime)
ORDER BY 1 DESC LIMIT 6