【发布时间】:2016-02-23 04:46:28
【问题描述】:
我正在开发一个酒店预订应用程序,您可以在其中选择日期和房间类型,该应用程序会显示可用房间。我正在使用 Java Spring 框架来执行此操作。
这是我认为对这个查询很重要的表:
CREATE TABLE IF NOT EXISTS `booking` (
`id` bigint(20) NOT NULL,
`aproved` bit(1) NOT NULL,
`begin_date` datetime DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`room_id` bigint(20) DEFAULT NULL,
`user_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `room` (
`id` bigint(20) NOT NULL,
`name` varchar(255) DEFAULT NULL,
`room_type_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=161 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `room_type` (
`id` bigint(20) NOT NULL,
`number_of_rooms` int(11) NOT NULL,
`price` int(11) NOT NULL,
`type` varchar(255) DEFAULT NULL,
`hotel_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;
我在进行该查询时遇到了困难...
我做了这个,但加入预订房间不是一个好主意,因为这只会在有预订时选择房间......
SELECT *
FROM room r join booking b on b.room_id = r.id join room_type rt on r.room_type_id = rt.id
WHERE not ((b.begin_date >= :initDate And b.begin_date <= :endDate) or (b.begin_date >= :initDate And b.end_date <= :endDate) or (b.begin_date <= :initDate and b.end_date >= :endDate) and b.aproved = true and rt.id = :roomType)
有什么想法吗?
【问题讨论】:
标签: mysql sql spring spring-mvc