I have an inventory database, and i need to calculate the quantity of products after each Buy or sell operation through my stock. So, i have three tables.The equation is like so :
(QtyInital + (BuyQuantity(IN) - SELLQUANTITY(OUT)
And Here is the schema of my three tables.
product(pid,name,qteInital,qteStock);
productInBuyFacture(baid,pid,qte,price,subtotal);
productInSellFacture(bsid,pid,qte,price,subtotal);
i want to calculate the current quantity of the stock via a trigger. I tried to do this via an SUB QUERYIES like so,
select ((select qteInital from product where id = 3) +
(select qte from productInBuyFacture where pid = 3 ) -
(select qte from productInSellFacture where pid = 3) as currentQuantity ;