I'm trying to use the coalesce function to return 0 when my query does not have a return value, but I have already tried a thousand and one shapes and can not return 0 at all. I want to know where I'm going wrong:
select
case
when date_part('month', p.data_cadastro) = 1 then '01.Jan'
when date_part('month', p.data_cadastro) = 2 then '02.Fev'
when date_part('month', p.data_cadastro) = 3 then '03.Mar'
when date_part('month', p.data_cadastro) = 4 then '04.Abr'
when date_part('month', p.data_cadastro) = 5 then '05.Mai'
when date_part('month', p.data_cadastro) = 6 then '06.Jun'
when date_part('month', p.data_cadastro) = 7 then '07.Jul'
when date_part('month', p.data_cadastro) = 8 then '08.Ago'
when date_part('month', p.data_cadastro) = 9 then '09.Set'
when date_part('month', p.data_cadastro) = 10 then '10.Out'
when date_part('month', p.data_cadastro) = 11 then '11.Nov'
else '12.Dez'
end as mes,
coalesce(count(*), '0'),
s.descricao as situacao
from
tb_historico p
inner join
tb_situacao s on s.id_situacao = p.id_situacao
where
date_part('year', p.data_cadastro) = 2015
and s.descricao = 'APROVADO'
and id_usuario = 10
and id_tipo_projeto = 1
group by mes, s.descricao
order by mes