How to sum the columns without multiplying the sums?

Asked

Viewed 23 times

0

When I run this query it sums the columns several times in the same number of outputs in the table itemsaida.

select p.idproduto codigo,
p.descricaoproduto nome,
sum(e.qtde) entrada,
sum(s.qtde) saida,
(sum(e.qtde) - sum(s.qtde)) as saldoestoque
from produto p
inner join itementrada e on p.idproduto = e.idproduto
inner join itemsaida s on p.idproduto = s.idproduto
where e.da between :data_inicial and :data_final
group by p.idproduto, p.descricaoproduto
order by p.descricaoproduto

Ex: There were two entrances, one of 100un and one of 230un and two exits of 1un each.

Should show input=330 and output=2, but shows input=990un and output=6un

inserir a descrição da imagem aquiinserir a descrição da imagem aqui

  • See if you can help https://answall.com/questions/466202/join-avan%C3%A7ado-em-Firebird-n%C3%A3o-can-join-the-tables-I-need-and-sort? noredirect=1

  • Thanks Motta. Helped and managed to solve the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.