Skip to content

Instantly share code, notes, and snippets.

@roberto-filho
Created March 29, 2014 12:29
Show Gist options
  • Select an option

  • Save roberto-filho/9853595 to your computer and use it in GitHub Desktop.

Select an option

Save roberto-filho/9853595 to your computer and use it in GitHub Desktop.
Query para buscar os lançamentos com data diferente da data da movimentação.
with q as (
select sum(case tipo
when 'D' then valor
else 0
end) debito,
sum(case tipo
when 'C' then valor
else 0
end) credito,
sum(valor) valor,
lote,
lcto.empresa_id,
lcto.datalancamento::date
from lancamentocontabil_lote lcto
join planoconta cc on lcto.conta_id = cc.id
where lcto.empresa_id = 225
group by lcto.empresa_id,
lote,
lcto.datalancamento::date
)
select razao_social(empresa_id), lote, datalancamento, debito-credito diff
from q
where debito <> credito;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment