使用Cake
PHP 1.2,我正在尝试生成一个GROUP BY查询:
SELECT `categories`.*,COUNT(`entities`.id) FROM `categories` LEFT JOIN `entities` ON (`categories`.`id` = `entities`.`category_id`) GROUP BY `categories`.`id`
这样做/我该怎么办?我正在使用“可容纳”,如果这有帮助.
这是我所了解的:
原文链接:https://www.f2er.com/php/139991.html$options = array( 'conditions' => $conditions,'fields'=>array('Category.*','COUNT(`Entity`.`id`) as `entity_count`'),'joins' => array('LEFT JOIN `entities` AS Entity ON `Entity`.`category_id` = `Category`.`id`'),'group' => '`Category`.`id`','contain' => array('Domain' => array('fields' => array('title'))) ); return $this->find('all',$options);