gpt4 book ai didi

MySQL 案例室可用性

转载 作者:行者123 更新时间:2023-11-30 00:04:07 25 4
gpt4 key购买 nike

我有 table :预订、预订、房间、住宿信息

样本数据:好的,首先对加密示例数据给您带来的不便表示歉意

这是与room_type相关的表

   mysql> SELECT
-> stay_info.room, room.code
-> FROM stay_info
-> RIGHT JOIN t_room
-> ON stay_info.room = room.code
-> INNER JOIN room_type
-> ON room_type.code = room.roomType
-> WHERE room_type.name = "Deluxe Double";




+--------------------------------------+--------------------------------------+
| room | code |
+--------------------------------------+--------------------------------------+
| NULL | 26a73433-d0cc-4e93-95d9-453d362e85a7 |
| NULL | 2b166d4f-2fe4-404c-beff-482c7d81c103 |
| NULL | 3efc3bff-9c02-43ef-a494-e887a342c1f5 |
| NULL | 7e0ebe37-a23a-46b6-9351-ba0c952ed33e |
| NULL | 9574eb5f-58de-427f-859e-d8b61e289836 |
| NULL | 9ee50e45-f92b-46bd-bf3e-fc818a96a81f |
| NULL | d72f3f7e-c9d2-44d8-8767-66d2a1477a1b |
| NULL | e25587a3-3dc1-4c0f-b4c2-68a1da538bd7 |
| NULL | e2d7fe3a-06e2-48df-a083-6c8eaeeefc22 |
| NULL | fadc4d40-33b2-4545-98fe-e52d351c50f9 |
+--------------------------------------+--------------------------------------+

一组 10 行(0.00 秒)

如果我有预订流程

mysql> SELECT
-> stay_info.room, IF(reservation.`status` = 1, room.code, (IF (stay
_info.room IS null , room.code,null))) as code
-> FROM stay_info
-> INNER JOIN reservation
-> ON reservation.stayInfo = stay_info.code
-> RIGHT JOIN room
-> ON stay_info.room = room.code
-> INNER JOIN room_type
-> ON room_type.code = room.roomType
-> WHERE room_type.name = "Deluxe Double" ;





+--------------------------------------+--------------------------------------+
| room | code |
+--------------------------------------+--------------------------------------+
| NULL | 26a73433-d0cc-4e93-95d9-453d362e85a7 |
| NULL | 2b166d4f-2fe4-404c-beff-482c7d81c103 |
| NULL | 3efc3bff-9c02-43ef-a494-e887a342c1f5 |
| NULL | 7e0ebe37-a23a-46b6-9351-ba0c952ed33e |
| NULL | 9574eb5f-58de-427f-859e-d8b61e289836 |
| NULL | 9ee50e45-f92b-46bd-bf3e-fc818a96a81f |
| NULL | d72f3f7e-c9d2-44d8-8767-66d2a1477a1b |
| e25587a3-3dc1-4c0f-b4c2-68a1da538bd7 | NULL |
| NULL | e2d7fe3a-06e2-48df-a083-6c8eaeeefc22 |
| NULL | fadc4d40-33b2-4545-98fe-e52d351c50f9 |
+--------------------------------------+--------------------------------------+

一组 10 行(0.00 秒)

所以 room.code 字段是可用房间。 booking.status = 1 表示预订无效,因此它将是可用房间,因为预订时的状态为 0,所以 room.code 为 NULL

预订详情中也发生同样的情况

   mysql> SELECT
-> stay_info.room, IF(booking_details.`status` = 1, room.code, (IF (stay_info.room IS null , room.code,null))) as code
-> FROM stay_info
-> INNER JOIN booking_details
-> ON booking_details.stayInfo = stay_info.code
-> RIGHT JOIN room
-> ON stay_info.room = room.code
-> INNER JOIN room_type
-> ON room_type.code = room.roomType
-> WHERE room_type.name = "Deluxe Double" ;





+--------------------------------------+--------------------------------------+
| room | code |
+--------------------------------------+--------------------------------------+
| 26a73433-d0cc-4e93-95d9-453d362e85a7 | NULL |
| NULL | 2b166d4f-2fe4-404c-beff-482c7d81c103 |
| NULL | 3efc3bff-9c02-43ef-a494-e887a342c1f5 |
| NULL | 7e0ebe37-a23a-46b6-9351-ba0c952ed33e |
| NULL | 9574eb5f-58de-427f-859e-d8b61e289836 |
| NULL | 9ee50e45-f92b-46bd-bf3e-fc818a96a81f |
| NULL | d72f3f7e-c9d2-44d8-8767-66d2a1477a1b |
| NULL | e25587a3-3dc1-4c0f-b4c2-68a1da538bd7 |
| NULL | e2d7fe3a-06e2-48df-a083-6c8eaeeefc22 |
| NULL | fadc4d40-33b2-4545-98fe-e52d351c50f9 |
+--------------------------------------+--------------------------------------+

一组 10 行(0.00 秒)

当我将上面的两个关系表与内连接结合起来

mysql> SELECT
-> stay_info.room,
-> IF((booking_details.`status` = 1 or reservation.`status` = 1), room.code, (IF (stay_info.room IS null , room.code,null))) as code
-> FROM stay_info
-> INNER JOIN booking_details
-> ON booking_details.stayInfo = stay_info.code
-> INNER JOIN reservation
-> ON reservation.stayInfo = stay_info.code
-> RIGHT JOIN room
-> ON stay_info.room = room.code
-> INNER JOIN room_type
-> ON room_type.code = room.roomType
-> WHERE room_type.name = "Deluxe Double" ;





+------+--------------------------------------+
| room | code |
+------+--------------------------------------+
| NULL | 26a73433-d0cc-4e93-95d9-453d362e85a7 |
| NULL | 2b166d4f-2fe4-404c-beff-482c7d81c103 |
| NULL | 3efc3bff-9c02-43ef-a494-e887a342c1f5 |
| NULL | 7e0ebe37-a23a-46b6-9351-ba0c952ed33e |
| NULL | 9574eb5f-58de-427f-859e-d8b61e289836 |
| NULL | 9ee50e45-f92b-46bd-bf3e-fc818a96a81f |
| NULL | d72f3f7e-c9d2-44d8-8767-66d2a1477a1b |
| NULL | e25587a3-3dc1-4c0f-b4c2-68a1da538bd7 |
| NULL | e2d7fe3a-06e2-48df-a083-6c8eaeeefc22 |
| NULL | fadc4d40-33b2-4545-98fe-e52d351c50f9 |
+------+--------------------------------------+

一组 10 行(0.00 秒)

我对这个组合的期望是

+--------------------------------------+--------------------------------------+
| room | code |
+--------------------------------------+--------------------------------------+
| 26a73433-d0cc-4e93-95d9-453d362e85a7 | NULL |
| NULL | 2b166d4f-2fe4-404c-beff-482c7d81c103 |
| NULL | 3efc3bff-9c02-43ef-a494-e887a342c1f5 |
| NULL | 7e0ebe37-a23a-46b6-9351-ba0c952ed33e |
| NULL | 9574eb5f-58de-427f-859e-d8b61e289836 |
| NULL | 9ee50e45-f92b-46bd-bf3e-fc818a96a81f |
| NULL | d72f3f7e-c9d2-44d8-8767-66d2a1477a1b |
| e25587a3-3dc1-4c0f-b4c2-68a1da538bd7 | NULL |
| NULL | e2d7fe3a-06e2-48df-a083-6c8eaeeefc22 |
| NULL | fadc4d40-33b2-4545-98fe-e52d351c50f9 |
+--------------------------------------+--------------------------------------+

这样我就可以从代码字段轻松获得可用房间

最佳答案

我已经找到了我自己问题的解决方案这就是解决方案

SELECT t_room_type.code, t_room_type.name,COUNT(t_room_type.name) AS numRoom FROM t_room INNER JOIN t_room_type ON t_room.roomType = t_room_type.code WHERE t_room.code NOT IN (SELECT DISTINCT t_stay_info.room FROM t_stay_info LEFT OUTER JOIN t_reservation ON t_stay_info.code = t_reservation.stayInfo LEFT OUTER JOIN t_booking_details ON t_stay_info.code = t_booking_details.stayInfo LEFT OUTER JOIN t_walk_in ON t_stay_info.code = t_walk_in.stayInfo LEFT OUTER JOIN t_stay_info_details ON t_stay_info.code = t_stay_info_details.stayInfo WHERE t_stay_info_details.stayDate BETWEEN '2014-07-16' AND '2014-07-17' AND (t_reservation.status = '0' OR t_booking_details.status = '0' OR t_walk_in.status = '0')) GROUP BY t_room_type.name ORDER BY t_room_type.name ASC

关于MySQL 案例室可用性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24749857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com