mysql查詢結果處理

mysql按月統計時,某月沒有數據 將此月補充並值爲0mysql

解決:建立一個月分表進行左鏈接sql

如圖是月份表spa

查詢時select

SELECT a.i months,IFNULL(b.count,0) count from 月份表 a LEFT JOIN (
select DATE_FORMAT(cjsj,'%m') months,count(*) count from 被查表 where year(cjsj)='2017'  group by monthsim

) b on a.i = b.months ORDER BY a.i統計

相關文章
相關標籤/搜索