在Cake中选择SUM

时间:2010-04-16 03:29:06

标签: cakephp select sum

当我尝试使用关注代码获取名为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);

我必须使用services[0][0]['servicecount']获取和数据,这看起来有点奇怪。我期望的是services['Serviceinfo']['servicecount'],或更简单的那个。那我怎么能解决这个问题?提前谢谢!< / p>

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

尝试为:

'SUM(Serviceinfo.services) as Serviceinfo.servicecount'