在codeigniter中使用sum加入查询

时间:2019-08-07 08:00:27

标签: mysql codeigniter join

我有三个表A,B和C,我正在取其列的总和,但来自表A的总和很好,但其他两个表的列总和使我的结果乘以2。即,如果表B中的一列是2,我在这里得到4。请帮助我

public function his()
    {   
        //current year
        $year=date("Y");
        $this->db->select('DATE_FORMAT(a.month, "%b") as mon,sum(a.zero_to_one_m+a.one_to_four_m) as mort,sum(b.total) as morb, sum(c.births) as live_births');
        $this->db->from('bhu_mortality a');
        $this->db->join('bhu_morbidity b','a.month=b.month');
        $this->db->join('bhu_live_births c','a.month=c.month');
        $this->db->where('YEAR(a.month)',$year);
        $this->db->order_by('a.month');
        $this->db->group_by('a.month');
        $data=$this->db->get()->result_array();
            return $data;

    }

0 个答案:

没有答案