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:
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:
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.