Finally ended up with this:
Never knew we could assign a variable as in first SELECT @total_cost:=....
That comes in handy....
Code:
SELECT @total_cost:=sum(round(r.rec_unit * r.rec_portion * gross_cost * 100) /100) from
FROM recipe_ingredient_data AS r
LEFT JOIN ingredient AS i
ON i.ingredient = r.rec_ingredient
WHERE r.rec_code = 'id3c9cb1714';
SELECT r.rec_ingredient AS Ingredient, i.gross_cost AS 'Bulk Price',
round(r.rec_unit * r.rec_portion * gross_cost * 100) /100 AS 'Ingredient Cost',
round(r.rec_unit * r.rec_portion * gross_cost * 100 / @total_cost ) AS '% of total'
FROM recipe_ingredient_data AS r
LEFT JOIN ingredient AS i
ON i.ingredient = r.rec_ingredient
WHERE r.rec_code = 'id3c9cb1714' ORDER BY r.rec_ingredient;
Bookmarks