有一种方法可以使用cakephp的agregate函数吗?比如sum()或avg()和find()方法.
更新:
我错过了书中的一句话
array('fields'=>array('Product.type','MIN(Product.price) as price'), 'group' => 'Product.type');
显示这样做的基本结构.
谢谢您的帮助
在find方法调用的fields参数中,您可以传递由聚合函数处理的字段.例:
$Model->find('all',
array(
'anything' => array(/* */),
'fields' => array(
'SUM (Model.attribute) AS total',
'OTHERFUNCTION(OModel.other_attribute) AS other'
),
'otherthing' => array(/* */)
)
);
Run Code Online (Sandbox Code Playgroud)