编辑代码

SELECT DATE_FORMAT(date_column, '%Y-%m') AS month  ,ifnull(b.records_count,0)
FROM your_table a
left join (select
DATE_FORMAT(t.`createTime`, '%Y-%m') AS month,
COUNT(*) as records_count
from testplanchangenodes t
left join me_testplan m on
m.`resourceID` = t.`testPlanResourceID`
where
m.source = 'pms'
and t.`afterChangeType` = 4000
and t.`beforeChangeType` != 4000
and t.`createTime` >= DATE_SUB(CURRENT_DATE(), INTERVAL 5 MONTH)
and m.sid = 1226
GROUP BY month
ORDER BY month) b on b.month = a.month
WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)  
GROUP BY month  
ORDER BY month

select a.month,ifnull(b.records_count,0) from (SELECT DATE_FORMAT(date_column, '%Y-%m') AS month  
FROM your_table  
WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)  
GROUP BY month  
ORDER BY month) a left join (select
DATE_FORMAT(t.`createTime`, '%Y-%m') AS month,
COUNT(*) as records_count
from testplanchangenodes t
left join me_testplan m on
m.`resourceID` = t.`testPlanResourceID`
where
m.source = 'pms'
and t.`afterChangeType` = 4000
and t.`beforeChangeType` != 4000
and t.`createTime` >= DATE_SUB(CURRENT_DATE(), INTERVAL 5 MONTH)
and m.sid = 1226
GROUP BY month
ORDER BY month) b on b.month = a.month