0

我通过 LEFT JOIN 在此查询中加入了许多表,我想在表上应用条件,但 php 给了我以下错误

错误号:1054 'on 子句'中的未知列'2021-08-23'

选择 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 投诉为 c LEFT JOIN 投诉部分为 cp ON c.complaint_Id = cp.cpart_Complaint_Id LEFT JOINscentres as s ON s.scentre_Id = c.complaint_Scentre_Id LEFT JOIN products as p ON p.product_Id = c.complaint_Product_Id 左连接模型为 m ON m.model_Id = c.complaint_Model_Id 左连接为 i ON i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '2021-08-23' AND '2021-08 -26' 其中 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");
4

2 回答 2

1

改变

 `2021-08-23` AND `2021-08-26`

'2021-08-23' AND '2021-08-26'

因为 ` 字符意味着列而不是字符串

于 2021-08-27T09:23:13.353 回答
0

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]);

于 2021-08-27T10:20:11.523 回答