SQL question answer this question: --Finding out all the guests who stayed in Gr
ID: 3815683 • Letter: S
Question
SQL question
answer this question:
--Finding out all the guests who stayed in Grosvenor hotel during September.
*according to the professor, there should be four conditions:
see this picture:
dateFrom >= 1/9 AND <= 30/9 --first condition
OR ( ) --second condition
OR ( ) --third condition
OR ( ) --fourth condition
*please also make the code as efficient as possible
Thank you!!
Schema Hotel (hotelNo, hotelName, city) Room (roomNo hotelNo, type, price) Booking (hotelNo uestNo, date Fro dateTo roomNo) Guest (guestNo, Nam guestAddress)Explanation / Answer
Here is the resultant query formed by joining the guest,hotel and booking tables on the common keys and adding the filter on hotelname and stay duration i.e. during september
SELECT * FROM Guest G,Hotel H,Booking B
WHERE
G.guestNo=B.guestNo /* to check whether the guest has an entry in booking table*/
AND B.hotelNo=H.hotelNo /*to check whether a booking is there for the hotel*/
AND H.HotelName='Grosvenor' /* to filter and retrieve the guests who stayed in Grosvenor*/
AND (B.dateFrom>='01/09' OR B.dateTo<='03/09' )/*To get the guests who stayed during september*/
Note:Could not add the type conversion functions as the date format is unknown .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.