Add values and subtract values from another condition

0

Good afternoon

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

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

There may be more than one payment for each title.

Under these conditions I need to put together a report that will bring me the value of open securities on a date.

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

NOTE: (Considering DTAOPERACAO < '01 -JAN-2017 for example)

    
asked by anonymous 19.05.2017 / 23:10

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;
    
31.05.2017 / 06:41