Mark lines where balance sum = 0

0

I have a table like this below, with the date, num, debit value, credit value, and balance sheet value (debit value + 0 - credit amount) and I need every time there is a value of debit and credit and the same document number, which are the same, or when the balance sum equals zero.

I tried to do a function but I only managed to signal when there are two records with the same number and the result of the balance gives 0, which in the example below would be the lines where num = 219900. But I wanted to flag all those that are between **. / p>

Can anyone help me?

data        num     debito   credito      balanco   zero_balanco
11/11/2016  219900          470,00      -470,00     Y
11/11/2016  219900  470,00              470,00      Y

01/11/2016  218295  163,00              163,00    
30/11/2016  218295  162,00              162,00      **Y**
30/11/2016  218295  162,00              162,00      **Y**
30/11/2016  218295          162,00      -162,00     **Y**
30/11/2016  218295          162,00      -162,00     **Y**
30/11/2016  218295  162,00              162,00  

25/10/2016  218102  935,46              935,46      **Y**
25/10/2016  218102          935,46      -935,46     **Y**
25/10/2016  218102  935,46              935,46

20/10/2016  217638  1.896,65            1.896,65    **Y**   
20/10/2016  217638          1.896,65    -1.896,65   **Y**   
20/10/2016  217638  1.896,65            1.896,65    **Y**   
20/10/2016  217638          1.896,65    -1.896,65   **Y**   
20/10/2016  217638  1.696,65            1.696,65    
    
asked by anonymous 19.12.2016 / 16:04

1 answer

0
select data , num , sum(credito) credito , sum(debito) debito ,         sum(credito-debito) balance ,
(case when sum(credito-debito) = 0 then 's' else 'n' end) zero_balanco
from tabela
where ....
group by data , num

I think this is, I hope I'm not simplifying

    
19.12.2016 / 16:18