Para hacer la consulta puedes anidar los meses de la siguiente manera:
select V.campo, (
select count(*)
from averias A
where A.fecha BETWEEN '2018-01-01' AND '2018-01-31' and A.campo=V.campo
) as ene,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-02-01' AND '2018-02-31' and A.campo=V.campo
) as feb,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-03-01' AND '2018-03-31' and A.campo=V.campo
) as mar,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-04-01' AND '2018-04-31' and A.campo=V.campo
) as abr,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-05-01' AND '2018-05-31' and A.campo=V.campo
) as may,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-06-01' AND '2018-06-31' and A.campo=V.campo
) as jun,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-07-01' AND '2018-07-31' and A.campo=V.campo
) as jul,(
select count(*)
from visita A
where A.fecha BETWEEN '2018-08-01' AND '2018-08-31' and A.campo=V.campo
) as ago,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-09-01' AND '2018-09-31' and A.campo=V.campo
) as sep,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-10-01' AND '2018-10-31' and A.campo=V.campo
) as oct,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-11-01' AND '2018-11-31' and A.campo=V.campo
) as nov,(
select count(*)
from averias A
where A.fecha BETWEEN '2018-12-01' AND '2018-12-31' and A.campo=V.campo
) as dic
from (select DISTINCT campo
from averias) V
Puede parecer extenso pero solo es como si hicieras las consultas por mes y las unieras en una sola, de esa forma puedes mostrar los registros por mes e imagino que cambiaras el año con php.
Otra solución es utilizar case
de la siguiente forma:
SELECT averias.centro,
SUM(CASE WHEN MONTH(averias.fecha) = 1 THEN 1 ELSE 0 END) AS Ene,
SUM(CASE WHEN MONTH(averias.fecha) = 2 THEN 1 ELSE 0 END) AS Feb,
SUM(CASE WHEN MONTH(averias.fecha) = 3 THEN 1 ELSE 0 END) AS Mar,
SUM(CASE WHEN MONTH(averias.fecha) = 4 THEN 1 ELSE 0 END) AS Abr,
SUM(CASE WHEN MONTH(averias.fecha) = 5 THEN 1 ELSE 0 END) AS May,
SUM(CASE WHEN MONTH(averias.fecha) = 6 THEN 1 ELSE 0 END) AS Jun,
SUM(CASE WHEN MONTH(averias.fecha) = 7 THEN 1 ELSE 0 END) AS Jul,
SUM(CASE WHEN MONTH(averias.fecha) = 8 THEN 1 ELSE 0 END) AS Ago,
SUM(CASE WHEN MONTH(averias.fecha) = 9 THEN 1 ELSE 0 END) AS Sep,
SUM(CASE WHEN MONTH(averias.fecha) = 10 THEN 1 ELSE 0 END) AS Oct,
SUM(CASE WHEN MONTH(averias.fecha) = 11 THEN 1 ELSE 0 END) AS Nov,
SUM(CASE WHEN MONTH(averias.fecha) = 12 THEN 1 ELSE 0 END) AS Dic
FROM averias
WHERE averias.fecha BETWEEN '2018-01-01' AND '2018-12-31'
GROUP BY averias.centro
Espero que sirva a los que lo necesiten. Saludos.
@the-breaker
si necesitas algo