I have the next question:
What is the most commonly booked room type for each hotel in New-York?
Tables:
1. Hotel - city, hotelNo[primarykey]
2. Room - roomNo[primarykey], type, hotelNo[foreignkey]
3. Booking - roomNo[foreignkey], hotelNo[foreignkey]
So, let’s say I have 3 hotels in the city and I need to get the table with columns:——–
NumberOfBookings, MostBookedType, HotelName
Any suggestions? Thanks in advance!
Here’s my code:
SELECT type, r.hotelNo, r.roomNo
FROM room r
INNER JOIN booking b ON r.roomNo=b.roomNo
WHERE r.hotelNo = ANY
(
SELECT hotelNo
FROM hotel
WHERE city = "New York"
)
It shows type of rooms, No of hotel, and roomNo of ever made bookings in hotels of New York.
I need to find out how to create a table showing type (that was mostly booked), numberOfBookings (of the most booked type), hotelNo (of the room type)
Now, this routine could pull Queen Bed from Hotel A first, with Double Bed from Hotel X second with Double Bed from Hotel A third, and King from Hotel A forth… As it appears you specifically wanted per hotel AND type of room…
I would ensure you have an index on your booking table based on (HotelNo, RoomNo) to help optimizing the group by…