Mark lines where balance sum = 0

Asked

Viewed 38 times

0

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

I tried to do a function but I could only 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 a = 219900. But I wanted to signal all those who are among ** .

Someone can 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    

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 that’s it, I hope I’m not simplifying

  • Unfortunately only that doesn’t work...

  • What’s the matter ?

  • thus, it only signals when the difference between credit and debit is zero... and yet, I have to be independent of the date, because a debit release in month 10 can be credited on later dates/months

  • Apart from the group by ?! select num , s .... group by num

Browser other questions tagged

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