Jump to content

Help me


Recommended Posts

Sql newbie here, Im stuck on a problem. 


I have a recipe ingredient table, and I want to calculate the price for a whole recipe rounded up to whole ingredient units. Every recipe has one row per ingredient and every ingredient has a price.

So I this sql. 

select recipe_id_label, recipe_name, variation_name, portion_size, menu_id, variation_name,
sum (recipe_order_ingredient_quantity * ingredient_expected_cost)
from mb.weekly_menus_recipes_ingredients
where recipe_id_label = '30943'
and portion_size = '2'
group by recipe_id_label, recipe_name, variation_name, portion_size, menu_id, variation_name

it works as long as there are only whole ingredients in the recipe. But if one ingredient has for example 0,25 packet of carrots, it gets the wrong result. Remember I want whole units.

So now I tried this 

sum (ingredient_planned_cost* ceiling (recipe_order_ingredient_quantity))

Still doesnt work, because if there are two halfs of the same ingredient it will sum those to two units. I want to round up the summed quantity, not every row by itself. 

And that's where Im stuck.


Edited by Hermii
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...