Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm being asked to create a couple of SQL statements to retrieve information about a Luxury Hotel Database.

List all the rooms in each hotel that have never been reserved in order by hotel number.
I have the SQL statement retrieved the rooms what have been reserved but my problem is retrieving those that have not been reserved.

SQL
SELECT RoomNo FROM RESERVATION WHERE RoomNo ORDER BY HotelNo


List the guests by name and the number of times each has reserved a room at one of our hotels. Arrange the list in order from most-frequent to least-frequent guest.

Here are the tables we are working on.

SQL
HOTEL (HotelNo, HotelName, City)

ROOM_TYPE (RoomType, Descr, RoomRate)

ROOM (HotelNo, RoomNo, RoomType, PhoneExt)
FK1: Foreign key HotelNo references HOTEL
FK2: Foreign key RoomType references ROOM_TYPE
GUEST (GuestNo, FirstName, LastName, Address, City, State, ZipCode)
GUEST_PHONE (PhoneNumber, GuestNo, PhoneType)
FK: Foreign key GuestNo references GUEST

RESERVATION (ResNum, HotelNo, RoomNo, GuestNo, ArrivalDate, DepartureDate, NumPersons)
FK1: Foreign Key (HotelNo, RoomNo) references ROOM
FK2: Foreign Key GuestNo references GUEST
Posted
Updated 10-Mar-15 1:05am
v2
Comments
CodingLover 8-Mar-15 21:51pm    
Do you know about inner/outer join?

Some tips to help you solve the problems:
1.
Quote:
List all the rooms in each hotel that have never been reserved in order by hotel number

How to => use NOT EXISTS[^] and ORDER BY (you should already know, else ask Google)
2.
Quote:
List the guests by name and the number of times each has reserved a room at one of our hotels. Arrange the list in order from most-frequent to least-frequent guest.

How to => Inner join[^] 2 related tables through primary key and foreign key, use COUNT Function[^], and ORDER BY.
 
Share this answer
 
v2
Quote:
I have the SQL statement retrieved the rooms what have been reserved but my problem is retrieving those that have not been reserved. SELECT RoomNo FROM RESERVATION WHERE RoomNo ORDER BY HotelNo


SQL
SELECT ROOM.HotelNo, ROOM.RoomNo 
from Room 
where ROOM.RoomNo Not In  (Select RESERVATION.RoomNo from RESERVATION)
Order by ROOM.HotelNo


would do you I think
 
Share this answer
 
Comments
[no name] 8-Mar-15 23:01pm    
List the guests by name and the number of times each has reserved a room at one of our hotels. Arrange the list in order from most-frequent to least-frequent guest.

My two related tables are Guest and Reservation.I can't have the FK GuestNo be one of the attributes.

Thus so far what I have
Hide Copy Code
Select FirstName, LastName, GuestNo FROM GUEST INNER JOIN RESERVATION ON GUEST.firstname = RESERVATION.guestno

I'm not sure about GuestNo.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900