I have a table with columns called:
If you can be absolutely sure there are no other variants of type other than 'charge' and 'discount', then this query should work:
select ID, sum(case when Type = 'charge' then Amount when Type = 'discount' then Amount*-1 end) as final_amount from my_table group by ID
It works by checking first what the type is before deciding what to contribute to the sum. If the value is a
'charge' then the amount is used, otherwise if the value is a
'discount' then the amount is negated and will be deducted from the sum.
discountare the only values possible for type