作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的查询
SELECT
tbl_rooms . *, tbl_property . *, tbl_bookings.booking_Id
FROM tbl_rooms
JOIN tbl_bookings ON tbl_rooms.room_id = tbl_bookings.room_id
JOIN tbl_property ON tbl_rooms.property_id = tbl_property.property_id
where
(tbl_bookings.From_date NOT BETWEEN CAST('2016-03-02' AS DATE) AND CAST('2016-03-06' AS DATE)
AND tbl_bookings.To_date NOT BETWEEN CAST('2016-03-02' AS DATE) AND CAST('2016-03-06' AS DATE)
AND tbl_bookings.From_date > CAST('2016-03-06' AS DATE)
AND tbl_bookings.To_date > CAST('2016-03-06' AS DATE) AND tbl_property.Ref_Property_Type_Property_Type_Id = 1)
当我尝试在codeigniter内实现此查询时我发现 BETWEEN 给出结果,但 NOT BETWEEN 没有给出任何结果,需要帮助...
编辑-codeigniter实现
$where="tbl_bookings.From_date NOT BETWEEN CAST('2016-03-02' AS DATE) AND CAST('2016-03-06' AS DATE)
AND tbl_bookings.To_date NOT BETWEEN CAST('2016-03-02' AS DATE) AND CAST('2016-03-06' AS DATE)
AND tbl_bookings.From_date > CAST('2016-03-06' AS DATE)
AND tbl_bookings.To_date > CAST('2016-03-06' AS DATE)";
$this->db->select('tbl_rooms.*,tbl_property.*,tbl_bookings.booking_Id');
$this->db->from('tbl_rooms');
$this->db->join('tbl_bookings','tbl_rooms.room_id = tbl_bookings.room_id' );
$this->db->join('tbl_property','tbl_rooms.property_id = tbl_property.property_id' );
$this->db->where($where);
$this->db->where('tbl_property.Ref_Property_Type_Property_Type_Id',1);
$query=$this->db->get();
最佳答案
其实这两个NOT BETWEEN AND
是没有用的,和下面两个条件重叠了。
该查询与以下查询等效:
SELECT
tbl_rooms . *, tbl_property . *, tbl_bookings.booking_Id
FROM tbl_rooms
JOIN tbl_bookings ON tbl_rooms.room_id = tbl_bookings.room_id
JOIN tbl_property ON tbl_rooms.property_id = tbl_property.property_id
where
tbl_bookings.From_date > CAST('2016-03-06' AS DATE) AND
tbl_bookings.To_date > CAST('2016-03-06' AS DATE) AND
tbl_property.Ref_Property_Type_Property_Type_Id = 1;
对于得到的空集,可能会被连接条件过滤掉。
您可以通过删除整个 where
子句来验证这一点。如果是这种情况,您需要进行相应的调整。
关于mysql - “NOT BETWEEN”在 codeigniter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36037063/
我是一名优秀的程序员,十分优秀!