-2

嗨,我想要一个查询来检索不在另一个表中的记录。例如(列出所有新加坡酒店空置的房间号)。

Room               Hotel            Booking
--------      --------------   ------------------
room_no          hotel_no           hotel_no
hotel_no         hotel_name         room_no
                                    date_from
                                    date_to

有没有办法只用一个 sql 查询来检索这条记录?

4

2 回答 2

1

你可以试试这个查询

 select room_no
   from room
  where room_no not in 
        (select room_no 
           from Booking 
          where hotel_no = singapore_hotel_no)
于 2013-07-26T04:56:52.787 回答
0
Select room.roon_num
from Room left outer join Hotel on room.room_no = hotel.room_no
left outer join Booking on room.room_no = booking.room_no and hotel.hotel_no = booking.hotel_no
where hotel.hotel_name = ? 
and not (? between (booking.date_from , booking.date_to))

这里第一个?'singapore hotel' 第二个?是您要查询的日期

于 2013-07-26T04:58:51.483 回答