SQL Queries for Sailor and Boat Reservations

This document provides SQL queries for retrieving information about sailors and their boat reservations. We have the following tables:

  • Sailors(sid: integer, sname: string, rating: integer, age: real)
  • Boats(bid: integer, bname: string, color: string)
  • Reserves(sid: integer, bid: integer, day: date)

Let's answer the following questions:

  1. Find the sid's of sailors who have made reservations between '20/9/2020' and '26/9/2020'. The results should not include repetitions. (20 Marks)
SELECT DISTINCT sid
FROM Reserves
WHERE day >= '2020-09-20' AND day <= '2020-09-26';
  1. Find the names and ages of sailors who have reserved boat bid 105. (30 Marks)
SELECT S.sname, S.age
FROM Sailors S
INNER JOIN Reserves R ON S.sid = R.sid
WHERE R.bid = 105;
  1. Find the sid's of sailors who have made reservations for the same boat on at least two different dates. (50 Marks)
SELECT sid
FROM Reserves
GROUP BY sid, bid
HAVING COUNT(DISTINCT day) >= 2;

Note: Please make sure to adjust the date format in the queries according to your database's date format.

SQL Queries for Sailor and Boat Reservations

原文地址: https://www.cveoy.top/t/topic/o7Gd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录