这是我的表格
create table guest (
guest_id int auto_increment primary key unique not null,
guest_lname varchar(50) not null,
guest_fname varchar(50) not null,
guest_email varchar(100) not null,
guest_password varchar(50) not null,
guest_address varchar(20) not null,
guest_op_adres varchar(200),
guest_gender int(1) not null,
guest_mobile_no varchar(15) not null
);
create table room_rate_default (
defroom_rateID int auto_increment not null primary key,
room_typeID int not null,
defseason_type varchar(50) not null,
defmonRate double not null,
deftuesRate double not null,
defwedRate double not null,
defthuRate double not null,
deffriRate double not null,
defsatRate double not null,
defsunRate double not null,
foreign key(room_typeID)references room_type(room_typeID)
);
create table room_rate (
room_rateID int auto_increment not null primary key,
room_typeID int not null,
season_type varchar(50) not null,
monRate double not null,
tuesRate double not null,
wedRate double not null,
thuRate double not null,
friRate double not null,
satRate double not null,
sunRate double not null,
adult int,
children int,
foreign key(room_typeID)references room_type(room_typeID)
);
create table room_type (
room_typeID int auto_increment not null primary key,
room_type varchar(50) not null,
room_type_des varchar(200)
);
create table room (
room_id int unique primary key auto_increment not null,
room_number int unique not null,
room_typeID int not null,
room_adultcapacity int not null,
room_childcapacity int not null,
room_img varchar(100),
room_status int(1),
foreign key(room_typeID)references room_type(room_typeID)
);
create table reservation (
reserve_code varchar(20) primary key unique not null,
guest_id int not null,
foreign key(guest_id)references guest(guest_id),
room_id int,
foreign key(room_id)references room(room_id),
reserve_date_start date,
reserve_date_end date,
reserve_status int(1)
);
这是记录
INSERT INTO `reservation` (`reserve_code`, `guest_id`, `room_id`, `reserve_date_start`, `reserve_date_end`, `reserve_status`) VALUES
('p28ypfgWO3Ijfn3eO5Vk', 18, NULL, 2, '2018-06-18', '2018-06-22', 1),
('67Bs8MKTOjZ2eJ9fxMPF', 18, NULL, 3, '2018-06-24', '2018-06-29', 1);
INSERT INTO `room` (`room_id`, `room_number`, `room_typeID`, `room_adultcapacity`, `room_childcapacity`, `room_img`, `room_status`) VALUES
(2, 102, 2, 2, 2, '../image-upload/room7.jpg', 1),
(3, 103, 2, 2, 2, '../image-upload/room8.jpg', 1),
(4, 104, 3, 2, 2, '../image-upload/room9.jpg', NULL),
(5, 105, 3, 2, 1, '../image-upload/room10.jpg', NULL);
这是从表单检查可用性中检入和签出日期
desire-check-in-dates date("2018-06-17")
desire-check-out-dates date("2018-06-23")
这是我的查询
"select distinct room_type.room_type, room_type.room_typeID, room_type.room_type_des, room.room_id, room.room_number, room.room_typeID, room.room_adultcapacity, room.room_childcapacity, room.room_img, room.room_status
from room
left outer join room_type on room.room_typeID = room_type.room_typeID
left outer join room_rate_default on room_type.room_typeID = room_rate_default.room_typeID
left outer join room_rate on room_type.room_typeID = room_rate.room_typeID
where room.room_id not in ('select room_id from reservation where date('2018-06-17') between
reserve_date_start and reserve_date_end or date('2018-06-23') between
reserve_date_start and reserve_date_end or date('2018-06-17') <
reserve_date_start and date('2018-06-23') > reserve_date_end') or room.room_status is null";
我不知道我的查询错误是什么.. 在这个查询中我想显示room_id 3,4和5,但我的查询不起作用..
答案 0 :(得分:0)
此查询现在正在运行 这是我的问题的答案 谢谢你先生@ P.Salmon寻求帮助
select distinct room_type.room_type, room_type.room_typeID, room_type.room_type_des, room.room_id, room.room_number, room.room_typeID, room.room_adultcapacity, room.room_childcapacity, room.room_img, room.room_status
from room left outer join room_type on room.room_typeID = room_type.room_typeID left outer join room_rate_default on room_type.room_typeID = room_rate_default.room_typeID
left outer join room_rate on room_type.room_typeID = room_rate.room_typeID
where room.room_id not in (select room_id from reservation where date('2018-06-17') between
reserve_date_start and reserve_date_end or date('2018-06-23') between
reserve_date_start and reserve_date_end or date('2018-06-17') <
reserve_date_start and date('2018-06-23') > reserve_date_end) or room.room_status is null