0
Good morning,
I have a problem where I have the following code working.
select
(sum((case when (lanc.id_tipo = 1 OR lanc.id_tipo = 5)
then lanc.valor else 0 end)) + sum((case when (lanc.id_tipo = 2)
then lanc.valor else 0 end))) AS Saldo
from lancamentos lanc
where lanc.id_situacao = 1 or lanc.id_situacao = 3 or lanc.id_situacao = 5
group by id_contas
I need to insert a filter, only it’s in another bank table, I have the accounts table and a column called id_tipo_conta
I would need him to add up only type 1, and I can’t get that filter into that code.
Someone can help me?
Is there supposed to be some kind of connection between these two tables (lancings and accounts), perhaps a foreign key? If it exists just make an INNER JOIN.
– anonimo
Add a left Join with the account table, then you can filter by account type in Where clause.
– Daniel Santos
Yes you do have the account Cod as foreign key...
– Victor Maziero