加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用包含多列的日期范围

发布时间:2020-12-13 16:55:04 所属栏目:PHP教程 来源:网络整理
导读:我有一个 mysql查询准备按日期范围搜索: select * from active_listings where open_date = '$start_date' AND open_date ='$end_date' 哪作得很好. 我在mysql中有两列:open_date和next_open_date.如何执行包含open_date和next_open_date的范围子句. 我试
我有一个 mysql查询准备按日期范围搜索:

select * from active_listings 
where open_date >= '$start_date' 
  AND open_date <='$end_date'

哪作得很好.

我在mysql中有两列:open_date和next_open_date.如何执行包含open_date和next_open_date的范围子句.

我试过做:

select * from active_listings 
where (open_date,next_open_date) >= '$start_date' 
  AND (open_date,next_open_date) <='$end_date')

我没有结果.

有人可以指导我或告诉我如何使用多列日期范围的方向.

谢谢!

解决方法

为避免歧义,您必须将范围分开,如下所示:

select * 
from active_listings 
where (open_date >= '$start_date' AND open_date <='$end_date') 
  OR (next_open_date >= '$start_date' AND next_open_date <='$end_date');

或者,更短一些:

select * 
from active_listings 
WHERE open_date BETWEEN '$start_date' AND '$end_date'
  OR next_open_date BETWEEN '$start_date' AND '$end_date';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读