I have a table that has the following columns:
- debit
- credit
- payment_method
- class
Now I will perform this query:
select sum(debit - credit), payment_method, class
from my_table
group by payment_method, class
And since I have various payment methods and various classes, I will have several rows of the result set.
Now I want to be able to aggregate this result and have the output grouped by class only, for example for a certain class 001
I want to have:
payment_method1, sumofpayment_method1, payment_method2, sumofpayment_method2, payment_method3, sumofpayment_method3
in one row.
Is it possible in Postgres 9.1?
Update:
The table definition is as follows:-
- debit numeric(10,2)
- credit numeric(10,2)
- payment_method varchar(20)
- class varchar(25)