views:

60

answers:

2

When I tried using follow code to get the sum of the column named Serviceinfo.services

$conditions = array('fields'=>array('SUM(Serviceinfo.services) as servicecount'),'conditions'=>array('time_id BETWEEN ? AND ?'=>array($startid,$endtid)));
$services = $this->Serviceinfo->find('all',$conditions);

I had to fetch the sum data with services[0][0]['servicecount'] which seems a little weird.And What I expect is services['Serviceinfo']['servicecount'],or more simple one.Then how can I fix this?Thanks in advance!

A: 

Try it as:

'SUM(Serviceinfo.services) as Serviceinfo.servicecount'
deceze
I've tried this and got a SQL syntax error.:-(
SpawnCxy
+1  A: 

See this link; http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/

Bjorn
That's helpful.thanks.
SpawnCxy