'Get one log per month, but if there are no logs keep the previous month's logs

I have this query that shows me the data created per month, if it doesn't show a 0, but my question is that I can fix it so that instead of 0, it is filled with the value of the previous month. Remember that two cumulative data per month

SET @csum := 0;
            SELECT 
            SUM(CASE WHEN fecha = 1   THEN (@csum := @csum + celulas) ELSE 0 END) AS ene,
            SUM(CASE WHEN fecha = 2   THEN (@csum := @csum + celulas) ELSE 0 END) AS  feb,
            SUM(CASE WHEN fecha = 3   THEN (@csum := @csum + celulas) ELSE 0 END) AS  mar,
            SUM(CASE WHEN fecha = 4   THEN (@csum := @csum + celulas) ELSE 0 END) AS abr,
            SUM(CASE WHEN fecha = 5   THEN (@csum := @csum + celulas) ELSE 0 END) AS may,
            SUM(CASE WHEN fecha = 6   THEN (@csum := @csum + celulas) ELSE 0 END) AS jun,
            SUM(CASE WHEN fecha = 7   THEN (@csum := @csum + celulas) ELSE 0 END) AS jul,
            SUM(CASE WHEN fecha = 8   THEN (@csum := @csum + celulas) ELSE 0 END) AS ago,
            SUM(CASE WHEN fecha = 9   THEN (@csum := @csum + celulas) ELSE 0 END) AS sep, 
            SUM(CASE WHEN fecha = 10  THEN (@csum := @csum + celulas) ELSE 0 END) AS oct,
            SUM(CASE WHEN fecha = 11  THEN (@csum := @csum + celulas) ELSE 0 END) AS nov,
            SUM(CASE WHEN fecha = 12  THEN (@csum := @csum + celulas) ELSE 0 END) AS dic
            FROM (
               SELECT MONTH(c.fecha_creacion) as fecha,COUNT(DISTINCT c.id_celulas) as celulas
               FROM lideres l 
               LEFT JOIN celulas c ON l.id_lideres = c.id_lideres
               WHERE l.id_sede = 372 AND DATE_FORMAT(c.fecha_creacion,'%Y-%m-%d') BETWEEN '2022-01-01' AND '2022-03-31'
               GROUP BY MONTH(c.fecha_creacion)
            ) AS temp
            ORDER by MONTH(fecha);

enter image description here : Outcome enter image description here : What I wish the result to be

My logs look something like this: enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source