Not sure if I'm even asking this correctly. I have a query that I am trying to display totals per each reason_id based on another tables qty value, but then group by months in the table where the reason_id exists.
My Query so far is:
select
month(f.c_date),
case when q.reason_id = 2 then sum(f.produced) else 0 end as 'LowM',
case when q.reason_id = 3 then sum(f.produced) else 0 end as 'LowP',
case when q.reason_id = 4 then sum(f.produced) else 0 end as 'LowSC',
from freeze f
inner join freezeq q on f.id = q.frz_id
inner join location l on f.t_id = l.id
where 1=1
and f.c_date like '%2018%'
group by q.reason_id, month(f.c_date);
I need to remove the "group by q.reason_id" but then of course the SUM values aren't separated.
I am trying to display the CASEs as columns and the SUM of the f.produced values, but group on the f.c_date.
I tried with sub queries a couple different ways, but can't seem to get it.
I appreciate any help the collective mind can give me!
Thanks!