0% found this document useful (0 votes)
135 views1 page

Practice Questions - Sailor Questions

The document provides 16 practice questions on SQL involving tables for sailors, boats, and reservations in a database. The questions ask the user to write SQL queries to find information like the colors of boats reserved by a specific sailor, sailor IDs meeting certain criteria, names of sailors matching conditions, and averages and groupings related to sailor ages, ratings, and boat reservations.

Uploaded by

John Gong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views1 page

Practice Questions - Sailor Questions

The document provides 16 practice questions on SQL involving tables for sailors, boats, and reservations in a database. The questions ask the user to write SQL queries to find information like the colors of boats reserved by a specific sailor, sailor IDs meeting certain criteria, names of sailors matching conditions, and averages and groupings related to sailor ages, ratings, and boat reservations.

Uploaded by

John Gong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practice Questions on SQL

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.

You might also like