php - using aggregate function in codeigniter query -
i trying write below query in codeigniter format , getting problem aggregate function:
$stmt = "select sum(subscription_amt) samt, bill_month, sum(loan_refund_amt*no_of_loan_installment+error_amt) lamt pf_bill_det trim(pf_number)='$pfno' , fin_year='$fyear' , aproved='y' group bill_month"; $query = $this->db->query($stmt);
this query ending error loan_refund_amt*no_of_loan_installment+error_amt not column
. please me how write query using codeigniter query format.
why don't try this
$this->db->select("count(*) mycount"); $this->db->from("mytable"); $this->db->where("field", $value); $this->db->get();
or
$this->db->select("sum(field_name) mysum"); $this->db->from("mytable"); $this->db->where("field", $value); $this->db->get();
or
$this->db->select("sum(field_name) mysum, username, password"); $this->db->from("mytable"); $this->db->where("field", $value); $this->db->get();
but
in simple query function can use
$query = $this->db->query("select count(field_name) total_names, fname");
$query->result(); \\ returns array of objects
$query->result_array(); \\ returns result pure array
$query->row(); \\ returns single result , first row
Comments
Post a Comment