Hello community The following query adds the occurrences of each activity state and then groups them by month
select
date_format(date_created, '%b') month,
month(date_created) pivot,
sum(case when a.state = 'created' then 1 else 0 end) created,
sum(case when a.state = 'notified' then 1 else 0 end) notified,
sum(case when a.state = 'confirmed' then 1 else 0 end) confirmed,
sum(case when a.state = 'approved' then 1 else 0 end) approved,
sum(case when a.state = 'authorized' then 1 else 0 end) authorized,
sum(case when a.state = 'attended' then 1 else 0 end) attended,
sum(case when a.state = 'canceled' then 1 else 0 end) canceled,
count(a.id) as total
from activities a
group by 1 order by pivot desc;
So I get the following result
I would like to add to this result the months in which there is no data and auto-complete the sums of state with zeros
I share this sqlfiddle
I found this answer to a similar scenario but I can not understand how I could apply it to the case that I present to you
Thank you very much for your help