-1

I have a table named 'money_table' as follow:

id    money_type    category    amount
1     EURO          CASH        2000
2     US_DOLLAR     CASH        3000
3     RUPEE         DD          4000
4     EURO          DD          5000
5     US_DOLLAR     DD          2000
6     EURO          CASH        6000
7     RUPEE         CASH        4500
8     US_DOLLAR     CASH        3000
9     EURO          NEFT        1000

I want results as below:

money_type    CASH    DD    NEFT
EURO          8000    5000  1000
US_DOLLAR     6000    2000  0
RUPEE         4500    4000  0

Thanks!

Armaan
  • 73
  • 3

1 Answers1

0

Try below using conditional aggregation

select money_type, sum(case when category='CASH' then amount end) as CASH,
sum(case when category='DD' then amount end) as DD,
sum(case when category='NEFT' then amount end) as NEFT
from tablename
group by money_type
Fahmi
  • 37,315
  • 5
  • 22
  • 31