How to find all pizzerias that serve every pizza eaten by people over 30?
Try doing a join using conditions rather than a cross. The conditions would be sure that you match up the records correctly (you only include them if they are in both relations) rather than matching every record in the first relation to every record in the second relation.
Definitely this is the concept of division operator in relational algebra.
But I tried on that course. The RA Relational Algebra Syntax doesn't support dev operator. So I used diff and cross instead. Here is my solution:
\project_{pizzeria}(Serves)
\diff
\project_{pizzeria}(
(\project_{pizzeria}(Serves)
\cross
\project_{pizza}(\project_{name}(\select_{age>30}(Person))\join Eats))
\diff
\project_{pizzeria,pizza}(Serves)
)
The solution is the join div operator http://en.wikipedia.org/wiki/Relational_algebra#Division_.28.C3.B7.29
See http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html
On slide 6, note that n is
(3 1 7)
.On the next slide,
o / n
results in(4 8)
.If
o
would also have(12 3)
and(12 1)
but not(12 7)
, 12 would not be part ofo / n
.
You should be able to fill in an example in the formula on Slide 16 and work it out.
In your case, we take
ɑ
to be:Chicago Pizza cheese cheese Chicago Pizza cheese supreme Chicago Pizza supreme cheese Chicago Pizza supreme supreme Dominos cheese cheese Dominos cheese supreme
Then we take
β
to be:cheese cheese cheese supreme supreme cheese supreme supreme
The result of
ɑ / β
would then be:Chicago Pizza
Dominos
is not part of this because it misses (supreme cheese)
and (supreme supreme)
.