Lab Assignment 5
Lab Assignment 5
• When writing a relational algebra it would work over all possible database instances and not
just for the given example instance!
ingredient
recipe
recipe foodItem ounces
name inventor kitchen Pasta and Meatballs Pasta 50
Pasta and Meatballs Le cook Italian Pasta and Meatballs Meatballs 10
Cheese Soup The french French Pasta and Meatballs Tomato Sauce 5
Burger Cowboys American
Pasta and Meatballs Onions 1
Cheese Soup Onions 4
Cheese Soup Cheese 15
foodItem Cheese Soup Bread 20
Burger Bread 10
item type calorie Burger Ground Beef 20
s
Pasta Wheat 20
product stock
Meatballs Meat 40
Tomato Sauce Sauce 5 foodIte shop price
Onions Vegetables 1 m
Cheese Diary 30 Pasta Aldi 5
Bread Wheat 25 Meatballs Aldi 10
product Tomato Aldi 3
Ground Beef Meat 45 Sauce
Tomato Walmart 3
Sauce
Hints:
Cheese Treasury 15
Island
Question 2
Write a relational algebra expression that returns food items that are sold at “Aldi” and their price.
Question 3
Write a relational algebra expression that returns food items (item) that are of type “Wheat product”
or of type “Meat” and have at least 20 calories per ounce (attribute calories).
Question 4
Write a relational algebra expression that returns the items and their price for all items of type “Wheat
product” sold at Aldi.
Question 5
Write a relational algebra expression that returns the names of all recipes that contain meat products
(food items of type “Meat”).
Question 6
Write a relational algebra expression that returns all recipes that contain both “Onions” and
“Cheese”.
Question 7
Write a relational algebra expression that returns the food items that are ingredients for “Cheese
Soup” but not for “Burgers”.
Question 8
Write a relational algebra expression that returns the total number of ounces for all ingredients per
recipe.
Question 9
Write a relational algebra expression that returns the average price of food items per type. For
example, this expression should return tuples like (Wheat product, 34.5).
Question 10
Write a relational algebra expression that returns the number of food item types for which the average
calories for all food items of this type is higher than 40.