hi all
I have one question . I my DB I have 3 tables
1)Products(id, name)
2)Incoming_products(id, quantity, measurement, product_id)
3)Outgoing_products(id, quantity, measurement, product_id)
now I need to calculate the difference between incoming and outgoing products.
I have a procedure but it doesn’t work correctly ( (
BEGIN
select incoming_products.product_id, sum(incoming_products.measurement)- sum(outgoing_products.measurement) as diff
from incoming_products, outgoing_products, products
where incoming_products.product_id=outgoing_products.product_id and incoming_products.product_id=products.id GROUP by incoming_products.product_id;
END
this procedure returns wrong values
if someone could help me, please reply this topic.