[英]Booking meeting rooms; Select available rooms in a given time period
I am making a meeting rooms booking system, where you choose a certain period of time and you should get available rooms at that time. 我正在制作一个会议室预订系统,您可以在该系统中选择一个特定的时间段,然后在那个时候获得可用的房间。 some of the tables s names are in french so i'll provide the meaning between () when needed.
某些表的名称是法文,因此在需要时我将提供()之间的含义。 My problem is that when i pick a time i get even not available rooms as available.
我的问题是,当我选择时间时,甚至没有可用的房间。 and i think my query has some problems.
而且我认为我的查询存在一些问题。 So, i have a reservation table,professor table and salle (means room in french) table.
因此,我有一个预订桌,教授桌和萨尔(法语中的指间)表。 The reservation table has the following columns : idReservation, dateReservation, hDebut (which is the starting time of the meeting), hFin(ending time), idSalle (room id)
预订表包含以下列:idReservation,dateReservation,hDebut(这是会议的开始时间),hFin(结束时间),idSalle(会议室ID)
Here are the create tables queries : please comment if you didn't understand some of the columns name who may be, like i said in french. 这是创建表的查询:如果您不理解某些列的名称(例如我用法语说的),请发表评论。
CREATE TABLE `reservation` (
`idReservation` int(11) NOT NULL,
`dateReservation` date DEFAULT NULL,
`hDebut` time NOT NULL,
`hFin` time NOT NULL,
`dateModificationReservation` date DEFAULT NULL,
`motifReservation` varchar(50) NOT NULL,
`idSalle` int(11) NOT NULL,
`idProf` int(11) NOT NULL,
`etatreserv` int(10) NOT NULL
)
etatreserv (2 for waiting, 1 for rejected, 0 for accepted)stands for the state of the room since the user send a request of booking a room for a cetrain time and the admin has the option to accept/reject even if the room is available etatreserv(等待2个,拒绝1个,接受0个)代表房间的状态,因为用户发送了一段预定时间的房间预订请求,并且管理员可以选择接受/拒绝,即使房间是可得到
INSERT INTO `reservation`(`idReservation`, `dateReservation`, `hDebut`, `hFin`, `dateModificationReservation`, `motifReservation`, `idSalle`, `idProf`, `etatreserv`) VALUES (1,'2019-06-14','15:00:00','18:00:00','2019-06-09','administrative meeting',1,12,2)
CREATE TABLE `salle` (
`idSalle` int(11) NOT NULL,
`intitule` varchar(40) NOT NULL,
`NumeroSalle` int(255) NOT NULL
)
INSERT INTO `salle` (`idSalle`, `intitule`, `NumeroSalle`) VALUES
(1, 'salle de reunion 1', 1),
(10, 'salle 18', 18);
CREATE TABLE `professeur` (
`idProf` int(11) NOT NULL,
`nomProf` varchar(50) NOT NULL,
`prenomProf` varchar(50) NOT NULL,
`tel` int(10) UNSIGNED NOT NULL,
`email` varchar(255) NOT NULL,
`profpwd` varchar(255) NOT NULL,
`dateAddProf` date NOT NULL,
`dateModificationProf` date NOT NULL,
`idDepart` int(11) NOT NULL
)
INSERT INTO `professeur` (`idProf`, `nomProf`, `prenomProf`, `tel`, `email`, `profpwd`, `dateAddProf`, `dateModificationProf`, `idDepart`) VALUES
(12, 'ddd', 'dd', 444, 'email@email.com', 'pwd', '2019-06-05', '2019-06-05', 5);
what i have tried already : 我已经尝试过的东西:
SELECT * FROM reservation left OUTER JOIN salle on reservation.idSalle = salle.idSalle WHERE (
(reservation.dateReservation IS NULL)
OR
(reservation.dateReservation != ':dateReservation')
OR
((reservation.dateReservation = ':dateReservation') AND (reservation.hDebut NOT BETWEEN ':hDebut' AND ':hFin') AND (reservation.hFin NOT BETWEEN ':hDebut' AND ':hFin'))
OR
((reservation.dateReservation = ':dateReservation') AND (reservation.hDebut >':hDebut' AND reservation.hFin <':hFin'))
)
and then i tried a more simplified version : 然后我尝试了一个更简化的版本:
dateReservation = ':dateReservation' AND
(hDebut BETWEEN ':hDebut' AND ':hFin' OR hFin BETWEEN ':hDebut' AND ':hFin' OR
(hDebut < ':hDebut' AND hFin > ':hFin'))))```
example :
salle table
idSalle | name
1 |salle de reunion 1
10 |salle18
3 |salle3
reservation table
idReservation|dateReservation|hDebut |hFin |idSalle
1 |2019-06-14 |15:00:00 |18:00:00 |1
if for example i choose dateReservation = 2019-06-14, hDebut=16:00:00,
hFin = 17:00:00 then all i should see are : salle2 and salle3
PS : I'm new to stackoverflow and the syntax highlighting confused me a bit, so I'm sorry if my code doesn't show up as it should.
DROP TABLE IF EXISTS salle;
CREATE TABLE salle
(salle_id SERIAL PRIMARY KEY
,name VARCHAR(12) UNIQUE
);
INSERT INTO salle VALUES
(1,'salle1'),
(2,'salle2'),
(3,'salle3');
DROP TABLE IF EXISTS reservation ;
CREATE TABLE reservation
(reservation_id SERIAL PRIMARY KEY
,reservation_from DATETIME NOT NULL
,reservation_to DATETIME NULL
,salle_id INT NOT NULL
);
INSERT INTO reservation VALUES
(1,'2019-06-14 15:00:00','2019-06-14 18:00:00',1);
SELECT s.*
FROM salle s
LEFT
JOIN reservation r
ON r.salle_id = s.salle_id
AND reservation_from <= '2019-06-14 17:00:00'
AND reservation_to >= '2019-06-14 16:00:00'
WHERE r.reservation_id IS NULL;
+----------+--------+
| salle_id | name |
+----------+--------+
| 2 | salle2 |
| 3 | salle3 |
+----------+--------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.