If I understand you well, you want to get one request
- MIN (Yacht.price) as min_price
- MAX (Yacht.price) as max_price
- MIN (Yacht.long) as min_length
- MAX (Yacht.long) as max_length
right?
You do not need any "Group By" sentence for this. The MIN and MAX functions are already aggregation functions. But nothing prevents you from using multiple aggregation functions in a single request.
Have you tried just doing this?
$stats = $this->Yacht->find(array( 'conditions' => $conditions, 'fields' => array( 'MIN(Yacht.price) as min_price', 'MAX(Yacht.price) as max_price', 'MIN(Yacht.long) as min_length', 'MAX(Yacht.long) as max_length' ) ) );
By the way, according to the documentation , there seems to be a lot of redundancy in your source code. "find (" first ", array (...))" by itself guarantees that you get only one result, therefore, there is no need to specify "limit" => 1 "in the query or" order ", since it should still there is only one field :)
Hope this helps.
source share