你好我有这个MYSQL QUERY
public function getInvoices($data,$date1,$date2)
{
$get = "Select count(*) as count,
str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
FROM affilitechargebackResponse
WHERE companyID = ".$data."
AND date >=".$date1."
AND date <=".$date2."
AND process = 1
group by yearweek(date);";
$query = $this->db->query($get);
return $query->result();
}
我不知道为什么没有任何东西会返回,即使我有数据库中的数据。当我删除行AND date <=".$date2."
时,代码将从db ...返回数据。我尝试BETWEEN仍然返回null
答案 0 :(得分:1)
AND date >=".$date1."
AND date <=".$date2."
到
AND date >='".$date1."'
AND date <='".$date2."'
答案 1 :(得分:0)
在单引号中使用日期,然后重试。
$get = "Select count(*) as count,
str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
FROM affilitechargebackResponse
WHERE companyID = ".$data."
AND date >='".$date1."'
AND date <='".$date2."'
AND process = 1
group by yearweek(date);";
答案 2 :(得分:0)
试试这个会起作用:
$get = "Select count(*) as count,
str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
FROM affilitechargebackResponse
WHERE companyID = ".$data."
AND date >='".$date1."'
AND date <='".$date2."'
AND process = 1
group by yearweek(date);";
从date1
和date2
删除双引号。使用单引号。