I am working on postgres and I would like you to help me add a column several times with different conditions for example I have my column days that are arrears of credits and the capital column that generates a credit, I need to group them as the table where they are grouped by greater than X days.
select
case
when bpatra > 30 then 'MAYOR A 30'
when bpatra > 60 then 'MAYOR A 60'
when bpatra > 90 then 'MAYOR A 90'
when bpatra > 150 then 'MAYOR A 150'
when bpatra > 180 then 'MAYOR A 180'
when bpatra > 270 then 'MAYOR A 270'
else null end as tramos,
round(sum(bpsalp + bpsali -bpadev -bpsusp))as riesgo,
round(((sum(bpsalp + bpsali -bpadev -bpsusp)/b.riesgototal)*100),2)
from
fsd012co,
(select sum(bpsalp + bpsali -bpadev -bpsusp) riesgototal from fsd012co where bpfec = current_date and bptip <> 'P' And bpmon = 6900) b
where
(bpfec = current_date)and
(bpmon = 6900) and
(bptip <>'P' )
group by
tramos,
b.riesgototal
order by
tramos