home / leitura

Maiores itens de cada tipo de gasto (todas as áreas)

Custom SQL query (hide)

select grupo, categoria, item, pago from (
  select grupo_gasto as grupo, categoria_gasto as categoria,
         case when classificacao = 'elemento' then ds_elemento_descricao else credor end as item,
         round(sum(vl_pago),2) as pago,
         row_number() over (partition by categoria_gasto order by sum(vl_pago) desc) as rn
  from empenhos
  where pilar = coalesce(nullif(:org,''),'prefeitura') and ano_exercicio = cast(:ano as integer) and status != 'ANULADO'
  group by 1,2,3 having sum(vl_pago) > 0
) where rn <= 8 order by pago desc

Query parameters

Edit SQL

0 results

Powered by Datasette · Queries took 8.585ms