The relations given below are part of a database schema for a hotel management s
ID: 3841838 • Letter: T
Question
The relations given below are part of a database schema for a hotel management system. Assume that these relations have been populated with suitable data as appropriate, and the underlined attribute is a primary key.
Hotel (hotelNo, hotelName, city)
Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Guest (guestNo, guestName, guestAddress)
where Hotel contains hotel details and hotelNo is the primary key;
Room contains room details for each hotel and (roomNo, hotelNo) forms the primary key;
Booking contains details of the bookings and (hotelNo, guestNo, dateFrom) forms the primary key; and
Guest contains guest details and guestNo is the primary key.
Write a relational algebra expression for each of the following data retrieval requirement:
(i) Produce a relation containing the hotel number of those hotels with a room price greater than £50.
(ii) Produce a relation containing the details of all rooms at all hotels.
(iii) Produce a relation containing all hotel names with a room price below £100.
(iv) Produce a relation containing all guests and show the details of any bookings they have beyond 1-Jun-2016.
Explanation / Answer
i) Produce a relation containing the hotel number of those hotels with a room price greater than £50.
select hotelno from hotel
where hotelno in (select hotelno
from room
where price >$50)
(ii) Produce a relation containing the details of all rooms at all hotels.
SELECT hotelNo, COUNT(roomNo) AS count FROM Room
GROUP BY hotelNo;
iii) Produce a relation containing all hotel names with a room price below £100.
select hotelname from hotel
where hotelno in (Select hotelno from room where price<$100)
iv) Produce a relation containing all guests and show the details of any bookings they have beyond 1-Jun-2016.
SELECT COUNT(DISTINCT guestNo) FROM Booking
WHERE dateFrom >= DATE’2016-06-01’
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.