Add values and subtract values from another condition

Asked

Viewed 428 times

1

Good afternoon

I have a table named TITLE In it I have columns with name CODOPERACAO, VLROPERACAO, DTAOPERACAO

I have 2 different records of CODOPERACAO that are: 16 = Inclusion of title 28 = Payment of the security

There may be more than one payment for each title.

Under these conditions I need to assemble a report that brings me the value of open securities on a date.

How do I add all CODOPERACAO = 16 and subtract by CODOPERACAO = 28 ?

NOTE: (This considering the DTAOPERATION < '01-JAN-2017' for example)

  • you need to have the relationship, saying that Transaction 28 is payment for Transaction 16, if you need to make a payment for multiple securities, it will have to be an n-n relationship, if not just put another column tying the source transaction

  • https://forum.imasters.com.br/topic/316225-resolver%C2%A0somar-2-values-same-field/ see if this helps

1 answer

0

select ID_TITULO, sum(decode(codoperacao, 28, -1, 1) * vlroperacao) sum_vlr_operacao 
from titulo 
where dtaoperacao <= '01-JAN-2017' 
group by ID_TITULO;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.