本文介绍了在65岁以内使用JOIN选择日期范围吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚安女士们和晚安!我试图在php发布脚本上提取一个查询,该脚本将提取信息

  SELECT`id` 
FROM`
WHERE'status` ='Passed'
AND`campaign_id` ='22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'

原始行是

  $ id_query = mysql_query(SELECT`id FROM`leads` WHERE`status` ='Passed'AND'campaign_id'='22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'); 
$ id = mysql_fetch_row($ id_query);
echo $ id [0];

因此,我想添加一个日期变量,选择大于65岁的

  BETWEEN(current_date  - DateField)> 365.0 * 65.0 

但显然这不行。我正在研究使用JOIN并添加

  AND'datesubmitted_c'BETWEEN Date_Add(curDate(),INTERVAL -65 YEARS)和curDate ()'
$ id_query = mysql_query(SELECT`id` FROM`leads` WHERE`status` ='Passed'AND'campaign_id'='22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'AND'datesubmitted_c'BETWEEN Date_Add(curDate(),INTERVAL -65 YEARS)和curDate()');

不完全确定使用加入是否合适?

解决方案

我想你正在寻找方法,以便您可以在范围之间进行检查。如下所示:

  SELECT * 
FROM mytable
WHERE _condition_1_
AND date_column BETWEEN CURDATE )AND DATE_ADD(CURDATE(),INTERVAL 65 YEAR)

哪个日期列 date_column 的日期从今天起至今年的65岁之间。


Good evening ladies and gents! I am attempting to pull a query on a php posting script that will pull information

SELECT  `id`
FROM    `leads`
WHERE   `status` = 'Passed'
  AND   `campaign_id` = '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'

original line is

$id_query  =  mysql_query("SELECT  `id` FROM  `leads` WHERE  `status` =  'Passed' AND     'campaign_id' =  '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee'"); 
$id = mysql_fetch_row($id_query); 
echo $id[0]; 

as such I wanted to add a date variable that will select greater then 65 years:

BETWEEN (current_date - "DateField") > 365.0 * 65.0

but obviously this does not work. I was looking into using JOIN and add

AND 'datesubmitted_c' BETWEEN Date_Add(curDate(), INTERVAL -65 YEARS) AND curDate()'
$id_query  =  mysql_query("SELECT  `id` FROM  `leads` WHERE  `status` =  'Passed' AND     'campaign_id' =  '22d0cf4f-0f81-28b1-d8dc-4f046bd1d8ee' AND 'datesubmitted_c' BETWEEN Date_Add(curDate(), INTERVAL -65 YEARS) AND curDate()'");

Not exactly sure if using a join would be appropriate?

解决方案

I think you're looking for the DATE_ADD method so you can check between a range. Something like:

SELECT  *
FROM    mytable
WHERE   _condition_1_
  AND   date_column BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 65 YEAR)

Which would check if the date column date_column has a date that falls between today's date and 65 years from now.

这篇关于在65岁以内使用JOIN选择日期范围吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:21