In: Computer Science
Product(p-id, p-name, weight)
Retailer(r-id, r-name, city)
Sells(r-id, p-id, price)
r-id is a foreign key referencing Retailer
p-id is a foreign key referencing Product
Give a Relational Algebra expression : (IT IS NOT SQL)
(a) Find the names of the retailers who are selling the products that have a weight greater than 10 kg.
(b) Find the names of the retailers who have never sold a product that has a weight greater than 10 kg.
(c) Get the price of the products that have a weight greater than 10 kg and have been sold by the retailers from Istanbul.
(d) Find the average price of each product that is sold.
These are the queries of relation algebra for the given problems.
where |X| symbol is used to represent the natural join between tables.
Explanation:
In the first what we are doing is we are first joining those rows/tuples which are common to all the tables by using natural join.After joning the tables we are selecting those rows which have weight greater than 10 using Selection operator then after that we are Projecting only the Name column.
In the similiar way we are selecting rows with weight not greater than 10 after joining the tables.
Then in third we are projecting Price column only by selecting rows with weight greater than 10 and place equals to Istanbul .
And in the last query we are first projecting only the Price column then passing in into the aggreagte function i.e AVG.