我想建立一个酒店预订系统。对于这个系统;数据库也用于其他程序...但我有问题:在预订之前我想看看我的预订可以使用哪种类型的房间类型..
我的表创建了sql querys
CREATE TABLE oteldb.oda (
oda_id INT (11) NOT NULL auto_increment,
oda_tip_id INT (11) DEFAULT NULL,
oda_adi VARCHAR (20) DEFAULT NULL,
PRIMARY KEY (oda_id)
)
ENGINE = MyISAM
AUTO_INCREMENT = 1
CHARACTER SET utf8
COLLATE utf8_general_ci;
CREATE TABLE oteldb.tip (
tip_id INT (11) NOT NULL auto_increment,
tip_adi VARCHAR (20) DEFAULT NULL,
PRIMARY KEY (tip_id)
)
ENGINE = MyISAM
AUTO_INCREMENT = 1
CHARACTER SET utf8
COLLATE utf8_general_ci
ROW_FORMAT = FIXED;
CREATE TABLE oteldb.rezervasyon (
rezervasyon_id INT (11) NOT NULL auto_increment,
rezervasyon_gt DATE DEFAULT NULL,
rezervasyon_ct DATE DEFAULT NULL,
rezervasyon_oda_id INT (11) DEFAULT NULL,
PRIMARY KEY (rezervasyon_id)
)
ENGINE = MyISAM
AUTO_INCREMENT = 1
CHARACTER SET utf8
COLLATE utf8_general_ci;
我尝试这个但不能正常工作
SELECT
*
FROM
oteldb.tip
WHERE
IN tip.tip_id
(SELECT
oteldb.oda.oda_tip_id
FROM
oteldb.oda
WHERE
IN oda.oda_id note
(SELECT
oteldb.rezervasyon.rezervasyon_oda_id
FROM
oteldb.rezervasyon
WHERE
"2012-01-03" BETWEEN AND rezervasyon_ct rezervasyon_gt
AND "2012-01-22" AND BETWEEN rezervasyon_gt rezervasyon_ct))
现在谢谢...
答案 0 :(得分:0)
select
RoomType.tip_adi,
sum( if( Rooms.oda_id = BookedRooms.rezervasyon_oda_id, 0, 1 ) as AvailableCount
from
oteldb.oda Rooms
LEFT JOIN ( select distinct
res.rezervasyon_oda_id
from
oteldb.rezervasyo res
where
res.rezervasyon_gt between '2012-01-22' and '2012-01-03'
OR res.rezervasyon_ct between '2012-01-22' and '2012-01-03'
) BookedRooms
on Rooms.oda_id = BookedRooms.rezervasyon_oda_id
JOIN oteldb.tip RoomType
on Rooms.oda_tip_id = RoomType.tip_id