Pizza(pizza)
Customers (cname,area)
Restaurants (rname,area)
Contains (pizza,ingredient)
Sells(rname,pizza,price)
Likes(cname,pizza)
Primary keys are bolded
Foreign keys are:
• Contains.pizza is a foreign key that refers to Pizzas.pizza.
• Sells.rname is a foreign key that refers to Restaurants.rname.
• Sells.pizza is a foreign key that refers to Pizzas.pizza.
• Likes.cname is a foreign key that refers to Customers.cname.
• Likes.pizza is a foreign key that refers to Pizzas.pizza.
Answer in Relational Algebra Format
Find all customer-pizza pairs (C, P) where the pizza P is sold by some restaurant
that is located in the same area as that of the customer C. Include customers
whose associated set of pizzas is empty.
a) πpizza (σpizza (cname='Alice' and cname<>'Bob') Likes )
b) πcanme,rname (σcname,rname (Customers ⋈ customers.area = restaurants.area Restaurants ⋈ restaurants.rname = sells.rname Sells ⋈ sells.pizza = likes.pizza Likes )
c) πLikes.cname,Pizza.pizza ( σ Likes.cname,Pizza.pizza(Likes.pizza<>Pizza.pizza) (Pizza x Likes) )
d) πL1.cname,L2.cname ( σL1.cname,L2.cname(L1.cname<>L2.cname and L1.pizza<>L2.pizza) (Likes L1 x Likes L2) )
e) πL1.cname,L2.cname ( σL1.cname,L2.cname(L1.cname<>L2.cname and L1.pizza=L2.pizza) (Likes L1 x Likes L2) )
f) πprice ( rname γ MAX(price) (Sells) ) -- γ is grouping symbol
g) πcname,pizza (σcname,pizza (Likes ⟖ Likes.cname = Customers.cname Customers ⋈ Customers.area = Restaurants.area Restaurants ⋈ restaurants.rname = sells.rname Sells) )
Comments
Leave a comment