I have a table similar to below
Date | institution | qty1 | qty2
1 Aug 12 | xyz | 0 | 5
1 Aug 12 | xyz | 0 | 17
1 Aug 12 | abc | 12 | 0
2 Aug 12 | abc | 33 | 0
2 Aug 12 | xyz | 0 | 57
I want output similar to below
Date | ABC | XYZ | Total
1 Aug 12 | 12 | 22 | 34
2 Aug 12 | 33 | 57 | 90
Total | 45 | 79 | 124
Now I have written a query which displays only first three columns. I don’t know how to add the last total column
select date, sum (case when institution = 'abc', qty1 else 0 end) as ABC,
sum(case when institution = 'xyz', qty2 else 0 end) as XYZ
group by date
with rollup
You are very close – I think this should do it:
Here is a link to this example on sqlfiddle.