1
Here is an example for testing where the Case command within the Sum function is used to multiply the value by -1 when the type is spent, and thus subtract:
select sum(valor * case when tipo = 'RECEITA' then 1 else -1 end) as resultado
from Tabela
I hope it helps
Need to add up all that revenue and subtract all that is expense? Or are there other conditions?
– tvdias
exactly, add up all that is revenue and subtract all that is expense, just.
– Edney Araujo
in this case, it seems that there is already a correct answer. if it solves your problem you must accept it.
– tvdias