Get the result of SUM and group field from Active record in Codeigniter

前端 未结 2 1017
执念已碎
执念已碎 2021-01-16 23:21

I need to build this query in Codeigniter but I don\'t know how to get the result of the SUM:

SELECT 
    description, SUM(amount)
FROM
    PAYMENT
WHERE
            


        
2条回答
  •  春和景丽
    2021-01-17 00:17

    try something like this:

    $query = $this->db->select_sum('amount', 'Amount');
    $query = $this->db->where(...)
    $query = $this->db->get('payment');
    $result = $query->result();
    
    return $result[0]->Amount;
    

提交回复
热议问题