Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (55.67 KB, 2 trang )
Chapter 5 - SQL
Tutorial
1. What are the two major components of SQL and what function do they serve ?
2. What are the advantages and disadvantages of SQL ?
3. The following tables form part of a database held in a relational DBMS.
Hotel (hotelNo, name, address)
Room (roomNo, hotelNo, type, price)
Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)
Guest (guestNo, name, address)
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 the primary key comprises hotelNo,
guestNo and dateFrom.
Guest contains guest details and guestNo is the primary key.
(a) Construct an SQL statement to answer the following queries.
(i) List full details of all hotels.
(ii) List full details of all hotels in London.
(iii) List the names and addresses of all guests in London, alphabetically
ordered by name.
(iv) List all double or family rooms with a price below 40.00 per night,
in ascending order of price.
(v) List the bookings for which no date_to has been specified.
(vi) How many hotels are there ?
(vii) What is the average price of a room ?
(viii) What is the total revenue per night from all double rooms ?
(viv) List the price and type of all rooms at the Grosvenor Hotel.
(x) List all guests currently staying at the Grosvenor Hotel.
(xi) What is the total income from bookings for the Grosvenor Hotel
today ?