You may need a table to store each month record. A temporary table can do the trick:
drop table if extists temp_months; create temporary table temp_months month date, index idx_date(month); insert into temp_months values ('2013-01-31'), ('2013-02-28'), ...
And now you can join your data with this newly created temp table:
SELECT COUNT( `userID` ) AS total, DATE_FORMAT( m.month , '%b' ) AS MONTH , YEAR( m.month ) AS year FROM months as m left join `users` as u on m.month = last_day(FROM_UNIXTIME(`userRegistredDate`, '%b' ) GROUP BY last_day(m.month);
Note that you can put the temp table creation (and populate) into the stored procedure.
I use last_day for simplicity, but you can use any date of the month that you like if you attach it correctly.
Hope this helps
source share