Practice Questions - Sailor Questions
Practice Questions - Sailor Questions
Try to solve as many problems as possible. You are not expected to complete this in one tutorial.
Go over these exercises before you attend your tutorial. For each exercise, try it first and discuss
with your TA any problems you may have.
Question
Consider the Sailors-Boats-Reserves DB described in the text.
s (sid, sname, rating, age)
b (bid, bname, color)
r (sid, bid, date)
Write each of the following queries in SQL.
1. Find the colors of boats reserved by Albert.
2. Find all sailor ids of sailors who have a rating of at least 8 or reserved boat 103.
3. Find the names of sailors who have not reserved a boat whose name contains the string
storm. Order the names in ascending order.
4. Find the sailor ids of sailors with age over 20 who have not reserved a boat whose name
includes the string thunder.
5. Find the names of sailors who have reserved at least two boats.
6. Find the names of sailors who have reserved all boats.
7. Find the names of sailors who have reserved all boats whose name starts with typhoon.
8. Find the sailor ids of sailors whose rating is better than some sailor called Bob.
9. Find the sailor ids of sailors whose rating is better than every sailor called Bob.
10. Find the sailor ids of sailors with the highest rating.
11. Find the name and age of the oldest sailor.
12. Find the names of sailors who have reserved every boat reserved by those with a lower
rating.
13. For each rating, find the average age of sailors at that level of rating.
14. For each boat which was reserved by at least 5 distinct sailors, find the boat id and the
average age of sailors who reserved it.
15. For each boat which was reserved by at least 5 sailors with age >= 40, find the boat id and
the average age of such sailors.
16. For each boat which was reserved by at least 5 sailors with age >= 40, find the boat id and
the average age of all sailors who reserved the boat.