Introduction to Databases with Stanford University : Relational Algebra Exercises

From Ittichai Chammavanijakul's Wiki
Revision as of 17:49, 16 November 2011 by Ittichai (talk | contribs)
Jump to navigation Jump to search

1. Find all pizzas eaten by at least one female over the age of 20.

\project_{pizza} ( 
 \select_{gender='female' and age > 20} Person 
  \join Eats) 

2. Find the names of all females who eat at least one pizza served by Straw Hat. (Note: The pizza need not be eaten at Straw Hat.)

\project_{name} ( 
  \select_{gender='female'} ( 
      ( \select_{pizzeria='Straw Hat'} Serves 
        \join Eats 
       ) \join Person 
   )
)

3. Find all pizzerias that serve at least one pizza for less than $10 that either Amy or Fay (or both) eat.

\project_{pizzeria} ( 
   \select_{name='Amy' or name='Fay'} ( 
      \select_{price < 10} Serves 
      \join Eats 
   ) 
)