0
The code below returns a sum per classification. Something like this: Services = type 1 Materials = type 2
the expected result is that there is only one row, and that in this Row I have the value of each type per column .
select distinct
C.COD,
c.paciente,
--C.CON || '-' || T.NOME Convenio ,
C.TIPO_CTA,
l.tipo,
sum (L.VALOR_C) over(partition by (L.TIPO) ) total
from FCCTAEXT C
LEFT join FCLANEXT L on C.ID = L.ID_FCCTAEXT
left join TBCONVEN T on (T.COD = C.CON)
left join RECADATE E on E.REG = C.REG_ATE
where
c.reg_ate = 1654385 and
C.IND_EMI = 'T'
and ((C.ANOPRO = 2021
and C.MESPRO = 7))
and C.TIPO_CTA = 'E'
and C.CON = 12
Is there any alternative to subselect to handle this case ?
this is a pivot... with sql is complicated, but you can generate the query dynamically or do this only in the result view
– Rovann Linhalis