SELECT
SUM(CASE WHEN current_date = P.dtInicio then 1 else 0 end) as "Dia",
SUM(Case when cast(EXTRACT(ISODOWWEEK FROM current_date) as integer)-1 = cast(EXTRACT(ISODOWWEEK FROM P.dtInicio) as integer)-1 then 1 else 0 end) as "Semana ",
SUM(Case when EXTRACT(MONTH FROM current_date) = EXTRACT(MONTH FROM P.dtInicio) then 1 else 0 end) as "Mês ",
COUNT(*) as "Trimestre"
FROM esiaprocesso p
LEFT JOIN esiaCategoriaEvento c ON p.cdCategoriaevento = c.cdCategoriaEvento
LEFT JOIN esiaTipoPendencia tp ON p.cdTipoPendencia = tp.cdTipoPendencia
WHERE date_part('year',p.dtInicio) >= 2018
And c.cdCategoriaEvento = 2
and tp.cdTipoPendencia = 1
and p.cdEntidade <> 526 |