Boa tarde senhores, tenho uma consulta que me retorna alguns campos preciso da soma deles, só que perante uma condição
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,) Não está funcionando!
Preciso de um total acumulativo para quando o tipo for igual a 'C' e quando for igual a 'D'.Ir somando os valores onde o tipo for igual a 'C' simplificando.