错误编号:1054 'on clause' 中的未知列“2021-08-23”
Error Number: 1054 Unknown column '2021-08-23' in 'on clause'
我通过 LEFT JOIN 在此查询中加入了许多 table,我想在 table 上应用条件,但 php 给我以下错误
Error Number: 1054 Unknown column '2021-08-23' in 'on clause'
SELECT i.isn_Add_Date, s.scentre_Name, i.isn_Job_No,cp.cpart_Part_Id,
cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount,
p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date,
c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount
FROM complaints as c LEFT JOIN complaint_parts as cp ON c.complaint_Id
= cp.cpart_Complaint_Id LEFT JOIN scentres as s ON s.scentre_Id = c.complaint_Scentre_Id LEFT JOIN products as p ON p.product_Id =
c.complaint_Product_Id LEFT JOIN models as m ON m.model_Id =
c.complaint_Model_Id LEFT JOIN isn as i ON i.isn_Complain_Number =
c.complaint_Job_No AND i.isn_Add_Date BETWEEN '2021-08-23' AND
'2021-08-26' WHERE c.complaint_Scentre_Id = '1' AND c.complaint_Status
= 'Delivered' AND c.complaint_Trash = 0
这是我的php代码
$this->db->select('i.isn_Add_Date,s.scentre_Name,i.isn_Job_No,cp.cpart_Part_Id,cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount,p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date,c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount');
$this->db->join('complaint_parts as cp', 'c.complaint_Id = cp.cpart_Complaint_Id ', 'left');
$this->db->join('scentres as s', 's.scentre_Id = c.complaint_Scentre_Id', 'left');
$this->db->join('products as p', 'p.product_Id = c.complaint_Product_Id', 'left');
$this->db->join('models as m', 'm.model_Id = c.complaint_Model_Id', 'left');
$this->db->JOIN('isn as i', 'i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '.str_replace('/', '-', $fromDate).' AND '.str_replace('/', '-', $toDate).'', 'LEFT');
$this->db->where("c.complaint_Scentre_Id", $serviceCenterId[0]);
$this->db->where("c.complaint_Status",'Delivered');
$this->db->where("c.complaint_Trash", 0);
$query = $this->db->get("complaints as c");
改变
`2021-08-23` AND `2021-08-26`
至
'2021-08-23' AND '2021-08-26'
因为 ` 字符表示列而不是字符串
sql没问题
也许 orm 无法处理复杂的连接条件
您可以将连接条件【AND i.isn_Add_Date BETWEEN '2021-08-23' AND '2021-08-26'] 移动到 where 条件
就像 $this->db->where("i.isn_Add_Date", BETWEEN ,['2021-08-23','2021-08-26]);
我通过 LEFT JOIN 在此查询中加入了许多 table,我想在 table 上应用条件,但 php 给我以下错误
Error Number: 1054 Unknown column '2021-08-23' in 'on clause'
SELECT i.isn_Add_Date, s.scentre_Name, i.isn_Job_No,cp.cpart_Part_Id, cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount, p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date, c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount FROM complaints as c LEFT JOIN complaint_parts as cp ON c.complaint_Id = cp.cpart_Complaint_Id LEFT JOIN scentres as s ON s.scentre_Id = c.complaint_Scentre_Id LEFT JOIN products as p ON p.product_Id = c.complaint_Product_Id LEFT JOIN models as m ON m.model_Id = c.complaint_Model_Id LEFT JOIN isn as i ON i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '2021-08-23' AND '2021-08-26' WHERE c.complaint_Scentre_Id = '1' AND c.complaint_Status = 'Delivered' AND c.complaint_Trash = 0
这是我的php代码
$this->db->select('i.isn_Add_Date,s.scentre_Name,i.isn_Job_No,cp.cpart_Part_Id,cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount,p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date,c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount');
$this->db->join('complaint_parts as cp', 'c.complaint_Id = cp.cpart_Complaint_Id ', 'left');
$this->db->join('scentres as s', 's.scentre_Id = c.complaint_Scentre_Id', 'left');
$this->db->join('products as p', 'p.product_Id = c.complaint_Product_Id', 'left');
$this->db->join('models as m', 'm.model_Id = c.complaint_Model_Id', 'left');
$this->db->JOIN('isn as i', 'i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '.str_replace('/', '-', $fromDate).' AND '.str_replace('/', '-', $toDate).'', 'LEFT');
$this->db->where("c.complaint_Scentre_Id", $serviceCenterId[0]);
$this->db->where("c.complaint_Status",'Delivered');
$this->db->where("c.complaint_Trash", 0);
$query = $this->db->get("complaints as c");
改变
`2021-08-23` AND `2021-08-26`
至
'2021-08-23' AND '2021-08-26'
因为 ` 字符表示列而不是字符串
sql没问题 也许 orm 无法处理复杂的连接条件
您可以将连接条件【AND i.isn_Add_Date BETWEEN '2021-08-23' AND '2021-08-26'] 移动到 where 条件
就像 $this->db->where("i.isn_Add_Date", BETWEEN ,['2021-08-23','2021-08-26]);