Jump to content

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...