Вопрос

This is a question from my database class's practice midterm. Say I have the following relational schema:

WorkList(EMP#, WorkType#, Season) EMP#, WorkType# and Season combine to form the primary key

(121, 1, Winter)
(121, 2, Winter)
(114, 1, Spring)
(114, 2, Spring)
(114, 2, Fall)

should return tuples

(114)

What is the relational algebraic expression I can use to return the workers who have at some point only worked on one WorkType# in a season? We can only use union, set minus, cartesian product, natural join, select, project, rename and intersection.

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

Решение

Without grouping operators, we have to do a little bit of a roundabout method to get the result needed:

  1. Take the Cartesian product of the table with itself (I'll now refer to the attributes as EMP1, EMP2, Worktype1, etc. Note for "proper" relational algebra, you would have to rename these attributes prior to the Cartesian product).

  2. Select tuples with EMP1 = EMP2, Season1 = Season2, WorkType1 != WorkType2. Note some definitions of relational algebra do not allow != in a predicate. It's still possible without it, but more workarounds would be needed. I'll assume I can use it.

  3. Project and rename EMP1, WorkType1, Season1 to your original attribute names. You now have a relation containing instances where a worker has worked on more than one work type in a season.

  4. Take the set difference of your original table with the one obtained in Step 3. This relation only has instances where a worker only worked on one work type in a season.

  5. Project the EMP# attribute.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top