Oracle Query


I have 3 fields with sampel data in oracle below.
I need to a query to get the total amount(group by ID). If type='D' the positive number, If Type='C' then it should be a negative number.

ID Type   Amount
1     D       200
2     C       100

Thanks in advance.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

awking00Connect With a Mentor Commented:
select id, type, decode(Type,'D',Amount,'C',-1 * Amount) Amount
sdstuberConnect With a Mentor Commented:
select id, sum(case when type  ='D' then amount else  -amount end) from yourtable
group by id
All Courses

From novice to tech pro — start learning today.