I’m trying to join 2 sql queries in one query.
The first one gets the count of rooms per hotel.
The second one gets the count of checked guests in hotel.
I’m trying to get occupancy rate per hotel.
SELECT hotel_id, count(room_id)
FROM room
group by room.hotel_id
SELECT h.hotel_id, count(k.room_id)
FROM room_reservation as kr , room as k , hotel as h
where kr.room_id = k.room_id and k.hotel_id = h.hotel_id
group by k.hotel_id
How can i do this ?
You can definitely do this with one query. One approach is just to union together your queries.
However, I think the following does what you want in one stroke:
I’m not positive, without knowing more about the tables. In particular, reservations have a time component which rooms and hotels don’t have. How is this incorporated into your queries?