这是一个创建我的表的查询:
CREATE TABLE IF NOT EXISTS `appschedule` (
`PID` varchar(200) NOT NULL,
`Surgery` varchar(200) NOT NULL,
`Activity` varchar(200) NOT NULL,
`Duration` int(11) NOT NULL,
`AppDate` datetime NOT NULL,
`AppSlot` varchar(20) NOT NULL,
`TimeFrom` varchar(200) NOT NULL,
`TimeTo` varchar(200) NOT NULL,
`StartTime` datetime NOT NULL,
`EndTime` datetime NOT NULL,
`AppTag` varchar(50) NOT NULL,
`Status` varchar(50) NOT NULL,
`AppID` varchar(200) NOT NULL,
`AppDateNum` varchar(20) NOT NULL,
`AppNum` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
这里是插入查询
INSERT INTO `appschedule`
(`PID`, `Surgery`, `Activity`, `Duration`, `AppDate`, `AppSlot`, `TimeFrom`,
`TimeTo`, `StartTime`, `EndTime`, `AppTag`, `Status`, `AppID`, `AppDateNum`,
`AppNum`)
VALUES
('PID-2014-06-02-00001', 'Single', 'Extraction Of Incisors', 10, '2014-07-03
00:00:00',
'Old', '17:30', '17:41', '2014-07-03 17:30:00', '2014-07-03 17:41:00',
'Single', '0', 'APP-2014-07-03-00001', '2014-07-03', 1);
现在我希望从上面的时间表中获得免费的时间段
所以我把这个查询
SELECT AvailStartTime, AvailEndTime
FROM
( SELECT @lastEndTime as AvailStartTime,
StartTime as AvailEndTime,
@lastEndTime := EndTime
FROM (SELECT StartTime, EndTime
FROM appschedule
WHERE AppDateNum = '2014-07-03'
AND AppDateNum = '2014-07-03'
AND EndTime >= '2014-07-03 17:30'
AND StartTime < '2014-07-03 21:30'
ORDER BY StartTime) e JOIN
(SELECT @lastEndTime := NULL) init) x
WHERE AvailEndTime > DATE_ADD(AvailStartTime, INTERVAL 10 MINUTE)
但我不知道为什么,它会给我留空数据。