SELECTDATE_FORMAT(date_column, '%Y-%m') ASmonth ,ifnull(b.records_count,0)
FROM your_table a
leftjoin (selectDATE_FORMAT(t.`createTime`, '%Y-%m') ASmonth,
COUNT(*) as records_count
from testplanchangenodes t
leftjoin me_testplan m on
m.`resourceID` = t.`testPlanResourceID`where
m.source = 'pms'and t.`afterChangeType` = 4000and t.`beforeChangeType` != 4000and t.`createTime` >= DATE_SUB(CURRENT_DATE(), INTERVAL5MONTH)
and m.sid = 1226GROUPBYmonthORDERBYmonth) b on b.month = a.month
WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL6MONTH)
GROUPBYmonthORDERBYmonthselect a.month,ifnull(b.records_count,0) from (SELECTDATE_FORMAT(date_column, '%Y-%m') ASmonthFROM your_table
WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL6MONTH)
GROUPBYmonthORDERBYmonth) a leftjoin (selectDATE_FORMAT(t.`createTime`, '%Y-%m') ASmonth,
COUNT(*) as records_count
from testplanchangenodes t
leftjoin me_testplan m on
m.`resourceID` = t.`testPlanResourceID`where
m.source = 'pms'and t.`afterChangeType` = 4000and t.`beforeChangeType` != 4000and t.`createTime` >= DATE_SUB(CURRENT_DATE(), INTERVAL5MONTH)
and m.sid = 1226GROUPBYmonthORDERBYmonth) b on b.month = a.month