Answer the question
In order to leave comments, you need to log in
How to display the warehouse with the largest number of goods and a unique product?
The essence of the task. Display those products (product.name), the balance of which in all warehouses in total exceeds 100 units (goods.quantity), indicating the warehouse (warehouse.namme) where the largest quantity is located.
select distinct product.name, warehouse.name, Sum(goods.quantity) AS "Count"
from product, warehouse, goods
where (goods.productId = product.id and goods.warehouseId = warehouse.id and goods.quantity >100 )
group by warehouse.name, product.name
order by warehouse.name asc, product.name asc
Answer the question
In order to leave comments, you need to log in
select distinct p.name, w.name, sum(g.quantity) as "count"
from product p, warehouse w, goods g
where (goods.productId = product.id and goods.warehouseId = warehouse.id
and p.id in
(select productid from
(select productid, sum(quantity) from goods group by productid having sum(quantity) > 100) sq1
) sq2
group by p.name, w.name
order by sum(g.quantity) desc
Using two subqueries .Crooked, but should work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question