SELECT
(ARRAY['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']) [date_part('MONTH', p.dtInicio)],
SUM(Case when EXTRACT(MONTH FROM p.dtInicio) = EXTRACT(MONTH FROM P.dtInicio) then 1 else 0 end) AS "Quantidade"
FROM esiaprocesso p
LEFT JOIN esiaCategoriaEvento c ON p.cdCategoriaevento = c.cdCategoriaEvento
WHERE date_part('year', p.dtInicio) = 2018
and c.cdCategoriaEvento = 2
and p.cdTipoPendencia = 1
and p.cdEntidade <> 526
and p.cdProduto in (3,10,12,4,8,16,21)
GROUP BY date_part('MONTH', p.dtInicio)
ORDER BY date_part('MONTH', p.dtInicio) |