Query in mysql eliminating zero results

0

Good morning once again I consult the community to see if you can help me, I have the following query:

SELECT ncuenta, dcuenta, SUM(-saldo) as monto2
FROM captura
WHERE SUBSTR(NCUENTA,1,2) >= '30'
and SUBSTR(NCUENTA,1,2) < '39'
and fecha <= '2017-09-30'
GROUP BY NCUENTA

Where the result is:

+---------+---------------+------------+
| ncuenta | dcuenta       | monto2     |
+---------+---------------+------------+
| 310-012 | revision      |      -0.00 |
| 320-005 | presupuesto   |       0.00 |
| 321-001 | datos ultimos | 5712934.19 |
+---------+---------------+------------+

And I get the query well but I would like the query to give me without the zero, that is to say:

+---------+---------------+------------+
| ncuenta | dcuenta       | monto2     |
+---------+---------------+------------+
| 321-001 | datos ultimos | 5712934.19 |
+---------+---------------+------------+

only someone who can help me or who has some idea of how I can do it

    
asked by Oscar Melendez 16.05.2018 в 19:20
source

2 answers

1

Try with:

SELECT ncuenta,dcuenta,SUM(-saldo) as monto2 FROM captura WHERE SUBSTR(NCUENTA,1,2)>='30'and SUBSTR(NCUENTA,1,2)<'39' and fecha<='2017-09-30'  GROUP BY NCUENTA HAVING SUM(-saldo)>0
    
answered by 16.05.2018 / 19:22
source
1
  

You can add in the where 2 conditionals pasted with an AND operator   so that it makes both comparisons including that it is greater than 0

SELECT ncuenta, dcuenta, SUM(-saldo) as monto2
    FROM captura
    WHERE 
       (SUBSTR(NCUENTA,1,2) >= '30') AND
       (monto2 > 0)
    and SUBSTR(NCUENTA,1,2) < '39'
    and fecha <= '2017-09-30'
    GROUP BY NCUENTA
  

Check very well that in order to pass more conditions to the WHERE the   separated between parentheses and separated by the AND operator

    
answered by 16.05.2018 в 20:26