此代码可以在特定日期内找到可用房间,但无法显示已预订和取消的房间
“酒店”有4个房间,其中1个已预订取消
所以即使我取消了,select方法也会给我3个结果。也许是因为第二个AND仍在运行。基本上我需要的是
SELECT RoomNo, NightCost
FROM room, room_types, booking
WHERE typeid = fk1_typeid
and double_bed=1
and single_bed=0
AND canceled = '1' in
(SELECT canceled
from booking, room_booking
where bookingid = fk2_bookingid)
AND RoomNo not in
(SELECT fk1_RoomNo
FROM room_booking
WHERE '2010-04-02' between Check_in
and Check_Out or
'2010-04-03' between Check_in
and Check_Out) ;
我试图尽可能清楚,如果需要我会提供更多细节
答案 0 :(得分:2)
SELECT *
FROM room
JOIN room_types
ON typeid = fk1_typeid
WHERE double_bed = 1
AND single_bed = 0
AND roomNo NOT IN
(
SELECT fk1_roomno
FROM room_booking
WHERE check_out >= '2010-04-02'
AND check_in <= '2010-04-03'
AND NOT canceled
)
答案 1 :(得分:0)
如果
,则在2010-04-02和2010-04-04之间占用一个房间当房间没有被占用时,房间是免费的
SELECT R.RoomNo, R.NightCost
FROM room as R
JOIN room_types as RT ON RT.typeid = R.fk1_typeid
WHERE (R.single_bed=0 and R.double_bed=1)
AND R.roomNo NOT IN (
SELECT RB.fk1_roomno
FROM room_booking as RB
WHERE (RB.check_out >= '2010-04-02')
AND (RB.check_in <= '2010-04-03')
AND NOT (RB.canceled=1)
)
这正是Quassnoi在我面前所说的..感叹: - )