Good afternoon gentlemen, I have a query that returns me some fields I need the sum of them, only that before a condition
select adm.adm_ds_administradora as descricao,
sum(car.car_vl_cartao) as valor,
'Cartão TEF' as cartao,
cast ('' as varchar) as fun_ds_funcionario,
cast ('' as varchar) as ntd_vl_acrescimo,
cast ('' as varchar) as ntd_vl_desconto,
cast ('' as varchar) as ntd_vl_pago,
cast ('' as varchar) as ntd_vl_saldo,
cast ('' as varchar) as agrupamento,
rank() over(
order by adm.adm_ds_administradora) as ordenacao,
adm.adm_fl_tipo,
*CASE WHEN adm.adm_fl_tipo = 'D' then
SUM(car.car_vl_cartao)
END as total,*
1 as CONSTANTE
from financeiro.cartao car,
cadastro.administradora adm
where car.car_cd_administradora = adm.adm_cd_administradora
and car.car_cd_caixa in (576785)
and adm.adm_ds_bandeira_tef is not null
group by adm.adm_cd_administradora
order by 3,
ordenacao,
1
( CASE WHEN adm.adm_fl_tipo = 'D' then SUM (car.car_vl_cartao) END as total, ) Not working!
I need a cumulative total for when type is equal to 'C' and when it is equal to 'D'.Ir adding values where type equals' C' simplifying.