query Sql bringing products that are with zero balance

1

I have the tables:

Produto                Departamento        
=========              ========
Id_Prod                id_Departamento                                       
Descricao              Descricao     


Produto_Departamento
=====================
id_Prod
Id_Departamento
Saldo                                              

Having the following scenario, I would like the help of you to develop this query.

I would like to bring all products whose balance sum is = 0. Remembering that the product can be registered in several departments

    
asked by anonymous 13.01.2016 / 18:08

1 answer

2

You did not specify very well, but I believe this example will help you:

select p.id_Prod, prod.Descricao from Produto_Departamento p
inner join Produto prod on prod.Id_Prod=p.Id_Prod
having sum(p.Saldo)>0
group by p.id_Prod,prod.Descricao
    
13.01.2016 / 19:01