php - Complex MySQL query, how to select all ingredients and get the quantity needed for orders -
i have query want list out ingredients on hand, , amount of ingredients needed orders outstanding. query works fine if ingredient being used in order, if has not been used in order yet not show ingredient in query.
is there way structure query shows ingredients , quantity on hand, amount needed outstanding orders?
suggestions appreciated. in advance. (*0.00220462 converts grams pounds)
select products.units, (orders_items.quantity - orders_items.quantity_baked) num_loaved_needed, inventory.title, inventory.id, round(inventory.quantity * 0.00220462,2) pounds, round(sum( (dough_recipes.grams / doughs.yield) * products.weight * (orders_items.quantity - orders_items.quantity_baked) * 0.00220462 ),2) amount_needed_for_all_current_orders orders_items left join products on products.id = orders_items.product_id left join doughs on doughs.id = products.dough_id left join dough_recipes on dough_recipes.dough_id = products.dough_id left join inventory on inventory.id = dough_recipes.inventory_id group inventory.id order title asc
Comments
Post a Comment