Only positive numbers in sum aggregation

5

In this query, in% w_that I would like to add only positive numbers, is there any way to do this?

    SELECT orcdotac.conta_desp 
       ,orcplade.descricao 
       ,orcplade.complemento 
       ,SUM(orcdotac.sld_orc_ano) AS CREDITOS_ORCAMENTARIOS 
       ,(SUM(orcdotac.SLD_ORC_ANO) + SUM(orcdotac.SLD_SUPL_ANO) + SUM(orcdotac.SLD_ESP_ANO) + SUM(orcdotac.SLD_EXT_ANO)) - SUM(orcdotac.SLD_RE_ANO) AS SALDO_ORCAMENTARIO 
       ,SUM(quota_re_mes1) AS NO_MES 
       ,(SUM(orcdotac.SLD_EMP_EMPEN) - SUM(orcdotac.SLD_EMP_ANULADO)) AS NO_ANO 
       ,(SUM(orcdotac.SLD_ORC_ANO) + SUM(orcdotac.SLD_SUPL_ANO) + SUM(orcdotac.SLD_ESP_ANO) + SUM(orcdotac.SLD_EXT_ANO)) - SUM(orcdotac.SLD_RE_ANO) - (SUM(orcdotac.SLD_EMP_EMPEN) - SUM(orcdotac.SLD_EMP_ANULADO)) AS DIFERENCAS 
FROM orcdotac 
LEFT JOIN orcplade ON 
        (orcdotac.conta_desp = orcplade.conta_desp) 
WHERE orcdotac.conta_desp IS NOT NULL and codigo_tipo = 1  
GROUP BY orcdotac.conta_desp, orcdotac.sub_item, orcplade.descricao, orcplade.complemento
ORDER BY conta_desp
    
asked by anonymous 05.06.2018 / 21:04

1 answer

4
....
, SUM(CASE WHEN quota_re_mes1 > 0 THEN quota_re_mes1 ELSE 0 END) AS NO_MES
....
    
05.06.2018 / 21:17