【发布时间】:2013-07-10 08:15:46
【问题描述】:
我在数据库中有一个名为 reservations 的表,其中包含以下列:id、date_from、date_to、obj_id.
在我的应用程序中,我需要创建一个 sql 查询,我可以在其中检查指定日期范围内的房间 (obj_id) 的可用性。
我试图使用类似以下的东西,但效果不佳:
select * from `reservations`
where ((`date_from` <= $from and `date_to` >= $from)
or (`date_from` <= $to and `date_to` >= $to)) and `obj_id` = $obj
例如,如果在 2013-07-03 至 2013-07-06 期间预订了某些房间,则将 2013-07-01 至 2013-07-07 的日期视为免费
【问题讨论】:
-
“工作不正常”不是正确的问题解释。
-
例如,2013-07-03 至 2013-07-06 预订房间时,2013-07-01 至 2013-07-07 的日期视为免费
-
提出问题