我有两个mysql表,日程表和约会。在日程表中有定义的医生终端,而在其他有预约的预约。问题是医生总是可以更改他的终端,我不能在约会表中粘贴参考,我只想在一个 mysql 查询中为两位医生获取可用的终端。那可能吗?
CREATE TABLE `schedule` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`from` timestamp NULL DEFAULT NULL,
`to` timestamp NULL DEFAULT NULL,
`doctor_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
INSERT INTO `schedule` (`id`, `from`, `to`, `doctor_id`)
VALUES
(1, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 1),
(2, '2012-09-06 15:00:00', '2012-09-06 15:59:59', 1),
(3, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 1),
(4, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 1),
(5, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 2),
(6, '2012-09-06 15:00:00', '2012-09-06 15:59:59', 2),
(7, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 2),
(8, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 2);
CREATE TABLE `appointments` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`from` timestamp NULL DEFAULT NULL,
`to` timestamp NULL DEFAULT NULL,
`doctor_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
INSERT INTO `appointments` (`id`, `from`, `to`, `doctor_id`)
VALUES
(3, '2012-09-06 16:00:00', '2012-09-06 16:59:59', 1),
(4, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 1),
(5, '2012-09-06 14:00:00', '2012-09-06 14:59:59', 2),
(8, '2012-09-06 17:00:00', '2012-09-06 17:59:59', 2);