home / leitura

Empenhos filtrados — maiores itens

Custom SQL query (hide)

select case when classificacao = 'elemento' then ds_elemento_descricao else credor end as item,
       round(sum(vl_pago),2) as pago, count(*) as n, max(case when classificacao <> 'elemento' and cnpj_cpf like 'PESSOA JUR%' then substr(cnpj_cpf,-14) end) as cnpj
from empenhos
where pilar = coalesce(nullif(:org,''),'prefeitura') and ano_exercicio = cast(:ano as integer) and status != 'ANULADO'
  and (:area = '' or ds_funcao_governo = :area) and (:grupo = '' or grupo_gasto = :grupo)
  and (:cat = '' or categoria_gasto = :cat) and (:modalidade = '' or ds_modalidade_lic = :modalidade)
  and (:q = '' or credor like '%' || :q || '%' or historico_despesa like '%' || :q || '%' or ds_elemento_descricao like '%' || :q || '%' or nr_empenho like '%' || :q || '%')
group by 1 having sum(vl_pago) > 0 order by pago desc limit 8

Query parameters

Edit SQL

0 results

Powered by Datasette · Queries took 9.848ms