加入 - 语法错误

时间:2015-10-30 07:34:37

标签: php mysql codeigniter

public function getIncomeBranches()
{   
    return
    $this->db->select('t1.subject_name, t2.payment_grand, t2,.payment_date, t3.level_id')
                     ->join('groups AS t3', 't1.subject_id = t3.group_id', 'left')
                     ->join('payments AS t2', 't1.subject_id = t2.payment_id')
                     ->group_by('t1.subject_id')
                     ->get("subjects AS t1")->result();
}

问题

  

错误号码:1064

     

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近' t3level_id FROM subjects AS t1 LEFT JOIN groups AS   t3 ON t1。“sub'在第1行

SELECT `t1`.`subject_name`, `t2`.`payment_grand`, `t2`, .`payment_date`, `t3`.`level_id` FROM `subjects` AS `t1` LEFT JOIN `groups` AS `t3` ON `t1`.`subject_id` = `t3`.`group_id` JOIN `payments` AS `t2` ON `t1`.`subject_id` = `t2`.`payment_id` GROUP BY `t1`.`subject_id`
  

文件名:   d:/www/domains/uzdev/taraqqiyot/application/models/Dashboard_model.php

     

行号:69

我想通过ID来记录主题并显示该主题的所有付款。

3 个答案:

答案 0 :(得分:3)

查询,中的不受欢迎的t2,.payment_date,只是将其从第一行删除

这将是

$this->db->select('t1.subject_name, t2.payment_grand, t2.payment_date, t3.level_id')
->join('groups AS t3', 't1.subject_id = t3.group_id', 'left')
                     ->join('payments AS t2', 't1.subject_id = t2.payment_id')
                     ->group_by('t1.subject_id')
                     ->get("subjects AS t1")->result();

答案 1 :(得分:0)

你的错误 - > t2,.payment_date,

public function getIncomeBranches()
{   
    return
    $this->db->select('t1.subject_name, t2.payment_grand, t2.payment_date, t3.level_id')
                     ->join('groups AS t3', 't1.subject_id = t3.group_id', 'left')
                     ->join('payments AS t2', 't1.subject_id = t2.payment_id')
                     ->group_by('t1.subject_id')
                     ->get("subjects AS t1")->result();
}

答案 2 :(得分:0)

t2,.payment_datet2.payment_date以及

$this->db->select('t1.subject_name, t2.payment_grand, t2.payment_date, t3.level_id')
    ->join('groups AS t3', 't1.subject_id = t3.group_id', 'left')
    ->join('payments AS t2', 't1.subject_id = t2.payment_id')
    ->group_by('t1.subject_id')
    ->get("subjects AS t1")->result();

加入时,语法就是这个,

 $this->db->join("table1","table1.id = table2.id");

如果正确,请检查第二次加入。