Вопрос

Currently in a database class and learning relational algebra and having a debate with another student over this statement

/Project pizza (/Select age < 24 (Person ⋈ Eats))

Will this statement give back all pizzas eaten by those under 24?

Schemas Here-

Person (name, age, gender)  
Frequents (name, pizzeria)  
Eats (name, pizza)      
Serves (pizzeria, pizza, price) 

My colleague believes that because we are projecting pizza and the person's schema does not include pizza that it won't work. However I believe because we join Person and Eats and thereby we create a new relation that we project the pizzas by and can select by age.

Это было полезно?

Решение

To get the right answer simple evaluate the expression:

Person /joins Eats

will result in a table where each person who eats a pizza is present. its schema is now:

(name, age, gender, pizza)

Now you select. The selection does not affect the schema, so its result's schema is the same.

Now you project pizza. The schema is simply (pizza).

So you have now projected the name of pizzas eaten by people under 24.

So yes, you are right. The JOIN creates a new table.

--dmg

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top