Calculate remain in stock

Calculate remain in stock


Hello,
I'm developing an app to control a small store. I have the table to registrate de products and other table to register the quantity of "buy" and "sell" movements of the products.

How do I do to sum all the "buy" and all the "sell" columns according to a product ID. Then calculate how many items remain in stock calculating  total_buy - total_sell of each product in the list.

Thanks

Rodny C.