MySQL: recuento por mes (incluidos los registros faltantes)
Tengo este SELECCIONAR:
SELECT
DATE_FORMAT(`created`, '%Y-%m') as byMonth,
COUNT(*) AS Total
FROM
`qualitaet`
WHERE
`created` >= MAKEDATE(year(now()-interval 1 year),1) + interval 5 month
AND
`status`=1
GROUP BY
YEAR(`created`), MONTH(`created`)
ORDER BY
YEAR(`created`) ASC
y obtén este resultado:
| byMonth | Total |
| 2015-06 | 2 |
| 2015-09 | 12 |
| 2015-10 | 3 |
| 2015-12 | 8 |
| 2016-01 | 1 |
verSQL-Fiddle aquí
La cláusula WHERE es importante porque la necesito como año fiscal actual a partir del 1 de junio, en mi ejemplo.
Como puede ver, no tengo registros para julio, agosto y noviembre. Pero necesito estos registros con cero en total.
Entonces mi resultado debería verse así:
| byMonth | Total |
| 2015-06 | 2 |
| 2015-07 | 0 |
| 2015-08 | 0 |
| 2015-09 | 12 |
| 2015-10 | 3 |
| 2015-11 | 0 |
| 2015-12 | 8 |
| 2016-01 | 1 |
¿Hay alguna manera de obtener este resultado?