服务器必须预留教室30分钟,1小时或一个半小时。
create database schooldb;
use schooldb;
CREATE TABLE `classrooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tipo` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `reserves` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` date NOT NULL,
`InitialTime` time NOT NULL,
`finalTime` time NOT NULL,
`classrooms_id_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_AA1DAB0188E95B37` (`classrooms_id_id`),
CONSTRAINT `FK_AA1DAB0188E95B37` FOREIGN KEY (`classrooms_id_id`) REFERENCES `classrooms` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
describe classrooms;
'id','int(11)','NO','PRI',NULL,'auto_increment'
'tipo','varchar(64)','NO','',NULL,''
describe reserves;
'id','int(11)','NO','PRI',NULL,'auto_increment'
'date','date','NO','',NULL,''
'InitialTime','time','NO','',NULL,''
'finalTime','time','NO','',NULL,''
'classrooms_id_id','int(11)','NO','MUL',NULL,''
INSERT INTO `schooldb`.`classrooms` (`id`, `tipo`) VALUES ('1', 'Physics');
INSERT INTO `schooldb`.`classrooms` (`id`, `tipo`) VALUES ('2', 'Circuits');
INSERT INTO `schooldb`.`reserves` (`id`, `date`, `InitialTime`, `finalTime`, `classrooms_id_id`) VALUES ('1', '2016-05-18', '09:30', '11:00', '1');
INSERT INTO `schooldb`.`reserves` (`id`, `date`, `InitialTime`, `finalTime`, `classrooms_id_id`) VALUES ('2', '2016-05-18', '12:00', '13:30', '1');
INSERT INTO `schooldb`.`reserves` (`id`, `date`, `InitialTime`, `finalTime`, `classrooms_id_id`) VALUES ('3', '2016-05-18', '19:00', '20:00', '1');
我需要获得所有可用时间范围,并使用PHP将其封装在JSON包中。例如:
select * from reserves;
'1','2016-05-18','09:30:00','11:00:00','1'
'2','2016-05-18','12:00:00','13:30:00','1'
'3','2016-05-18','19:00:00','20:00:00','1'
select * from reserves where date="2016-05-18" and InitialTime <= "09:30" and finalTime >= "10:00";
'1','2016-05-18','09:30:00','11:00:00','1'
行!它有效!!
现在:
select * from reserves where date="2016-05-18" and InitialTime <= "18:30" and finalTime >= "19:30";
没有结果!!错误!!
我该怎么做呢。
谢谢!