当我在codeigniter中使用此查询时:
$this->db->where("dopuex_donation_id", $donation_id);
$this->db->select("donation_purposes_expenses.*, SUM(donation_purposes_expenses.dopuex_withdrawn_value) AS count, cases.case_name");
$this->db->from("donation_purposes_expenses");
$this->db->join("expenses", "donation_purposes_expenses.dopuex_expense_id = expenses.expense_id", "left");
$this->db->join("cases", "expenses.expense_type = 1 && expenses.expense_case_ref_id = cases.case_ref_id", "left");
$this->db->group_by("cases.case_name");
return $this->db->get()->result_array();
我得到这个错误
Unknown column '1' in 'on clause'
SELECT `donation_purposes_expenses`.*, SUM(donation_purposes_expenses.dopuex_withdrawn_value) AS count, `cases`.`case_name` FROM (`donation_purposes_expenses`) LEFT JOIN `expenses` ON `donation_purposes_expenses`.`dopuex_expense_id` = `expenses`.`expense_id` LEFT JOIN `cases` ON `expenses`.`expense_type` = `1` && expenses.expense_case_ref_id = cases.case_ref_id WHERE `dopuex_donation_id` = '34' GROUP BY `cases`.`case_name`
它认为值1作为字段..我该如何解决?
最佳答案
只需交换条件并在条件之间放置AND
$this->db->where("dopuex_donation_id", $donation_id);
$this->db->select("donation_purposes_expenses.*, SUM(donation_purposes_expenses.dopuex_withdrawn_value) AS count,
cases.case_name");
$this->db->from("donation_purposes_expenses");
$this->db->join("expenses", "donation_purposes_expenses.dopuex_expense_id = expenses.expense_id",
"left");
$this->db->join("cases", "expenses.expense_case_ref_id = cases.case_ref_id AND expenses.expense_type = 1 ", "left");
$this->db->group_by("cases.case_name");
return $this->db->get()->result_array();
关于mysql - 'on子句'代码初始化器中的未知列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54732905/