我有以下查询:
SELECT DATE_FORMAT(login_date,'%M') AS month, COUNT(login_date) AS total
FROM login_history
GROUP BY year(login_date), month(login_date)
ORDER BY year(login_date) DESC, month(login_date) DESC
当前结果是:
++++++++++++++++++++++
+ month | total +
++++++++++++++++++++++
+ January | 53 +
++++++++++++++++++++++
+ November | 23 +
++++++++++++++++++++++
+ October `| 72 +
++++++++++++++++++++++
+ August | 9 +
++++++++++++++++++++++
+ July | 29 +
++++++++++++++++++++++
+ June | 53 +
++++++++++++++++++++++
我试图将输出保留为最近5个月,如果该月没有结果,则希望显示0。当前,如果没有值,查询将跳过月份。
++++++++++++++++++++++
+ month | total +
++++++++++++++++++++++
+ January | 53 +
++++++++++++++++++++++
+ December | 0 +
++++++++++++++++++++++
+ November | 23 +
++++++++++++++++++++++
+ October `| 72 +
++++++++++++++++++++++
+ September | 0 +
++++++++++++++++++++++