1. Consider the following schema: Manufacturer (MName, HQAddress, Country)
Car (Make, ModelNum, MName, Kind) Dealership (DName, DAddress) Sell (DName, Make, ModelNum) Use the relational Algebra to express the following queries: a. Find the makes of all cars manufactured by GM b. Find the names and addresses of all dealers who sell Mazda (i.e., cars with make Mazda.) c. Find the addresses of dealers that sell at least one make of car manufactured by a company incorporated in Canada. Solution: a.
Make(MName=GM (Car))
b. Dealership.Dname,DAddress(DealershipMake=Mazda(Sell)) (Natural Join where
Dname=DName done automatically) c. (Temp1, MName(Country=Canada(Manufacturer)) (Temp2, Make,ModelNum(Temp1 Car)) (Nat Join where MName= MName) (Temp3, DName(Temp2 Sell)) DAddress(Dealership Temp3) Alternative Solution DAddress(DName (Make,ModelNum((MName(Country=Canada(Manufacturer))) Car) Sell) Dealership) 2. Consider the following relation schemas: Cars (Make, Model, Year, VINNumber) Customers (Id, Name) Rentals (Id, VINNumber, Date) Use the relational algebra to answer the following query: Find all customer names who have previously rented every Volvo made in year 2016
Solution: Name(Customers ( ID,VINNumber(Rentals) / VINNumber ( Make=Volvo AND
Year=2016 (Cars))))
3. Consider the following SQL query:
SELECT P.Name, C.Name FROM Professor P, Course C, Taught T WHERE P.Id = T.ProfId AND T.Semester = Fall2015 AND T.CrsCode = C.CrsCode Write down an equivalent expression in relational algebra Solution: Professor.Name,Course.Name (Professor Id=ProfId ( Course Semester=Fall2015 Taught)) 4. Given the following schema: Student (Id, Name) Transaction (StudId, CourseName, Semester, Grade) Formulate the following query in SQL: Create a list of all students (Id, Name) and, for each student, list the average grade for the courses taken in the Fall2015 semester. Note that there can be students who did not take any courses in Fall2015. For these, the average grade should be listed as 0.