Advertisement
snovvblind

CS145 - Stanford - Relational Algebra Exercise

Oct 30th, 2011
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Relational Algebra Reference Guide: http://www.db-class.org/course/resources/index?page=ra
  2. Databases in Use: http://www.db-class.org/course/resources/index?page=pizzadata
  3.  
  4.  
  5. 1. Find all pizzas eaten by at least one female over the age of 20.
  6.  
  7. \project_{pizza} (
  8. (\project_{name}
  9. \select_{gender='female' and age > 20}
  10. Person
  11. )
  12. \join Eats
  13. )
  14.  
  15. 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.)
  16.  
  17. \project_{name}(
  18. (\project_{name}
  19. \select_{gender='female'}
  20. Person
  21. )
  22. \join
  23. (
  24. ( Eats)
  25. \join
  26. ( \select_{pizzeria='Straw Hat'} Serves)
  27. )
  28. )
  29.  
  30. 3. Find all pizzerias that serve at least one pizza for less than $10 that either Amy or Fay (or both) eat.
  31.  
  32. \project_{pizzeria} (
  33. ( \select_{price < 10} Serves )
  34. \join
  35. ( \select_{name='Amy' or 'Fay'} Eats )
  36. )
  37.  
  38. 4. Find all pizzerias that serve at least one pizza for less than $10 that both Amy and Fay eat.
  39.  
  40. \project_{pizzeria} (
  41. ( \select_{price < 10} Serves )
  42. \join
  43. ( \select_{name='Fay'} Eats )
  44. )
  45.  
  46. 5. Find the names of all people who eat at least one pizza served by Dominos but who do not frequent Dominos.
  47.  
  48. \project_{name}
  49. (\select_{pizza='cheese' or pizza='mushroom'} Eats
  50. \join Person)
  51. \diff \project_{name}(\select_{pizzeria='Dominos'} Frequents
  52. \join Person)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement