Mysql
 sql >> Database >  >> RDS >> Mysql

come ottenere la somma di una colonna con la query codeigniter

Puoi usare select_sum() funzione di code-accenditore. Prova il seguente codice-

$query = $this->db->select_sum("tb1.amount")
                  ->from("table1 as tb1")
                  ->join("table2 as tb2","tb1.id = tb2.id") 
                  ->where("tb2.status",1)
                  ->get();
$query = $query->result();

O

$query = $this->db->query('SELECT sum(tb1.amount) FROM table1 as tb1 join table2 as tb2 on tb1.id = tb2.id where tb1.status = 1'); $query = $query->result_array();