1

I encountered this question while revising for my finals exam on database theory.

The following database contains information about car repair workshops. The following tables are used:

enter image description here

Given two workshops W1 and W2, W1 is more expensive than W2 if for every car C that is repaired by both W1 and W2, the repair price for W1 is higher than the repair price for W2 for C. Write a relational algebra query to find all workshops (W1, W2) where W1 is more expensive than W2. Exclude workshops that do not repair any common cars.

I attempted to use a join naively:

  1. $\rho_{(w1,car,c1)}(Repairs) \bowtie_{car} \rho{(w2,car,c2)} \rightarrow A$
  2. enter image description here

And then simply project out the rname on a join with Workshop. However, I realised that there would exist some Repairs where c1 < c2 and c1 > c2 are both present, and it would still indicate that W1 is more expensive than W2.

I am thinking of using the division operator, but I am not sure how to proceed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.