Uploaded by Faleo Baller

Relational Algebra 1 Class Exercises - Solutions

advertisement
Relational Algebra 1
Class Exercises Solutions
Books Database
Authors (authorID, firstName, lastName, city, state)
Books (ISBN, authorID, title, copyright, price, PID)
Publishers (publisherID, pname, city)
Relational algebraic symbols: σ, π, ρ, , , , ⋈, , ∩, 
1.1 Books with a price greater than or equal to $25
σprice>=25(Books)
1.2 Publishers who are located in Boston, sorted by publisher name
pname σcity=’Boston’(Publishers)
1.3 Authors in the state of Florida. Rename the resulting relation AuthorsFL, sort by city in descending
order.
city desc ρAuthorsFL(σstate=’FL’(Authors))
1.4 First name and last name of authors who live in Chicago. Sort by last name then by first name.
 lastName, firstName πfirstName, lastName (σcity=’Chicago’(Authors))
or more concisely by dropping the parentheses
 lastName, firstName πfirstName, lastName σcity=’Chicago’(Authors)
1.5 List the title and price + $100 (call the attribute PremiumPrice) for books that have a copyright after
2000
πtitle, price + 100 AS PremiumPriceσcopyright>2000(Books)
NewBooks(ISBN, authorID, title, copyright, price, PID)
1.6 Including new books, list the title and copyright.
πtitle,copyright(Books  NewBooks)
NewBooks(ISBN, authorID, title, copyright, price)
1.7 Including new books, list the title and copyright.
πtitle,copyright(Books)  πtitle,copyright(NewBooks)
Note the missing PID!
Download