I have achieved your objective by constructing the sql query in following way:
SELECT min(Day
) time , SUM(CY-3
) ‘2019’, SUM(CY-2
) ‘2020’, SUM(CY-1
) ‘2021’, SUM(CY
) ‘2022’ FROM (
SELECT
Day
, month(Day
) ‘Maand’,
max(case WHEN year(Day
)=year(CURRENT_DATE) then graad_dag
else 0 END) ‘CY’,
max(case WHEN year(Day
)=year(CURRENT_DATE)-1 then graad_dag
else 0 END) ‘CY-1’,
max(case WHEN year(Day
)=year(CURRENT_DATE)-2 then graad_dag
else 0 END) ‘CY-2’,
max(case WHEN year(Day
)=year(CURRENT_DATE)-3 then graad_dag
else 0 END) ‘CY-3’
FROM hist_utils
WHERE year(Day
)>year(CURRENT_DATE)-4
GROUP BY Day
) as a
WHERE 1
GROUP BY Maand
ORDER BY Maand
;
And the graph looks like this: