显示可用性MySQL

时间:2017-06-08 16:47:20

标签: mysql

我已经使用下表设置了一个数据库。

CREATE TABLE `appointment` (
    `ID` INT(11) NOT NULL AUTO_INCREMENT,
    `DoctorID` INT(11) NOT NULL DEFAULT '0',
    `UserID` INT(11) NOT NULL DEFAULT '0',
    `Date` DATETIME NOT NULL,
    `Report` TEXT NULL,
    PRIMARY KEY (`ID`),
    INDEX `FK_appointment_doctors` (`DoctorID`),
    INDEX `FK_appointment_users` (`UserID`),
    CONSTRAINT `FK_appointment_doctors` FOREIGN KEY (`DoctorID`) REFERENCES `doctors` (`ID`),
    CONSTRAINT `FK_appointment_users` FOREIGN KEY (`UserID`) REFERENCES `users` (`ID`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=7
;

CREATE TABLE `availability` (
    `ID` INT(11) NOT NULL AUTO_INCREMENT,
    `DoctorID` INT(11) NOT NULL,
    `STime` DATETIME NULL DEFAULT '0000-00-00 00:00:00',
    `ETime` DATETIME NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`ID`),
    UNIQUE INDEX `ID_DoctorID_STime` (`ID`, `DoctorID`, `STime`),
    UNIQUE INDEX `DoctorID_STime` (`DoctorID`, `STime`),
    CONSTRAINT `FK_availability_doctors` FOREIGN KEY (`DoctorID`) REFERENCES `doctors` (`ID`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=33
;

CREATE TABLE `doctors` (
    `ID` INT(11) NOT NULL AUTO_INCREMENT,
    `Name` VARCHAR(100) NOT NULL DEFAULT '0',
    `Surname` VARCHAR(100) NOT NULL DEFAULT '0',
    `Email` VARCHAR(150) NOT NULL DEFAULT '0',
    `Password` VARCHAR(512) NOT NULL DEFAULT '0',
    `Specialty` VARCHAR(150) NOT NULL DEFAULT '0',
    `RegisteredDate` DATE NULL DEFAULT NULL,
    PRIMARY KEY (`ID`),
    UNIQUE INDEX `Email` (`Email`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=9
;

我想显示医生的可用性,但不是显示预约的时间。 请注意,每次约会都要持续一小时。

我正在尝试找到合适的查询,但我不能。所以,到目前为止,我已经完成了下图中的结果。 我认为我必须按小时分割可用的日期时间因为进一步开发我希望将结果显示给某些用户,以便他们可以创建约会。任何帮助都将受到赞赏。

这是表格和一些数据的SQL小提琴。 http://sqlfiddle.com/#!9/e1804a

约会表及其数据 Appointments Table and its Data

可用性表及其数据

Availability Table and its Data

在不考虑约会表的情况下显示可用性

Display availability without taking consideration the appointment table

期望的结果

Panagiotis | Cardiologist | March 01 2017 08:00:00 | March 01 2017 16:00:00
Panagiotis | Cardiologist | March 02 2017 08:00:00 | March 02 2017 16:00:00
Panagiotis | Cardiologist | March 03 2017 08:00:00 | March 03 2017 16:00:00
Panagiotis | Cardiologist | March 04 2017 08:00:00 | March 04 2017 16:00:00
Panagiotis | Cardiologist | March 05 2017 08:00:00 | March 05 2017 12:00:00
Panagiotis | Cardiologist | March 05 2017 13:00:00 | March 05 2017 16:00:00
Panagiotis | Cardiologist | March 06 2017 08:00:00 | March 06 2017 12:00:00
Panagiotis | Cardiologist | March 06 2017 13:00:00 | March 06 2017 16:00:00
Panagiotis | Cardiologist | March 07 2017 08:00:00 | March 07 2017 16:00:00
Panagiotis | Cardiologist | March 08 2017 08:00:00 | March 08 2017 16:00:00
Panagiotis | Cardiologist | March 09 2017 08:00:00 | March 09 2017 16:00:00

0 个答案:

没有答案