Msofts
Msofts

Reputation: 87

SUM and Group by field does not retrieve data

How I can retrieve data from the SUM(total) field? The following code does not produce a value in sum_tot:

$bill_receipts = $this->BanquetBillMaster->find('all', 
                    array('conditions' => array('status' => 2),
                          'fields' => array('id', 'total', 
                                  '(SUM(total)) AS sum_tot','booking_master_id'),
                          'group' => 'booking_master_id',
                          'contain' => false));

foreach($bill_receipts as $aa)
{
    echo $aa['BanquetBillMaster']['sum_tot'];
}  

Upvotes: 1

Views: 1928

Answers (1)

JJJ
JJJ

Reputation: 33163

Try to print the array with debug( $bill_receipts );, the sum_tot field is probably in $aa[ 0 ][ 'sum_tot' ]. Named fields are placed outside the "normal" structure.

Upvotes: 3

Related Questions