how to write distinct and count query in cakephp using find -


how write below query in cakephp using find .

$this->tmp_sale->query("select  distinct count( tax ) 'tax_amount' , sum( quantity ) 'quantity1',tax,tax_amount1 tmp_sale employee='$emp' , no ='$no' , store='$store_name' group tax"); 

you want find 'all' on tmpsale model , define fields count , sum:-

$data = $this->tmpsale->find(     'all',     array(         'fields' => array(             'count(tax) tax_amount',             'sum(quantity) quantity1',             'tax',             'tax_amount1'         ),         'conditions' => array(             'employee' => $emp,             'no' => $no,             'store' => $store_name         ),         'group' => array(             'tax'         )     ) ); debug($data); 

i've included debug($data) @ end you'll want take @ array returned perhaps not in format you'd expect due count , sum fields.


Comments