I have a table that contains entries based on expense purchases. If there are three columns that I need results from (department, month, total) like below.
dept | month | total
--------------------
aaaa | octob | 8
aaaa | octob | 4
aaaa | novm | 143
bbbb | octob | 42
bbbb | novm | 116
bbbb | novm | 117
bbbb | decm | 5
I would like to see a results set like this:
dept | oct | nov | dec
----------------------
aaaa | 12 | 143 | 0
bbbb | 42 | 233 | 5
Not exactly what you are asking for, but the way I would accomplish this is the following:
This will return a result set like:
etc. Then you can order and use in code to get the format you want above.
For exactly what you asked for it is something like:
Although I am not entirely sure this works correctly with group by.