Consider a database consisting of the following tables (relations): SAILORS(sid,
ID: 3740775 • Letter: C
Question
Consider a database consisting of the following tables (relations):
SAILORS(sid, name, rating, age)
BOATS(bid, name, color)
RESERVED(sid, bid, day) Write SQL statement for each of the following queries.
(1) Find the bids of the boats whose name is “storm”.
(2) Find the bids of the boats whose name contains the string “storm”.
(3) Find the names of the sailors who have a rating of at least 5.
(4) Find the names of boats whose color is yellow.
(5) Find the names of the sailors who have a rating of at least 5 and reserved a red boat.
Explanation / Answer
-- (1) Find the bids of the boats whose name is “storm”.
SELECT bid
FROM BOATS
WHERE `name` = 'storm';
-- (2) Find the bids of the boats whose name contains the string “storm”.
SELECT bid
FROM BOATS
WHERE name LIKE '%storm%';
-- (3) Find the names of the sailors who have a rating of at least 5.
SELECT `name`
FROM SAILORS
WHERE rating>=5;
-- (4) Find the names of boats whose color is yellow.
SELECT `name`
FROM BOATS
WHERE color = 'yellow';
-- (5) Find the names of the sailors who have a rating of at least 5 and reserved a red boat.
SELECT S.`name`
FROM SAILORS S, RESERVED R, BOATS B
FROM S.sid = R.sid AND R.bid = B.bid AND S.rating >= 5 AND B.color = 'red';
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.