我有这个 MySQL 查询:
SELECT DISTINCT hours.project_id
, projects.name
, sum(hours.spent_hours) AS expr1
, sum(hours.invoiced_hours) AS expr2
, hours.description
FROM
projects
INNER JOIN hours
ON projects.id = hours.project_id
GROUP BY
hours.project_id
, projects.id
, projects.name
, hours.description
你会如何在 CakePHP 中的 FIND 方法中放置片段?我尝试了几次,但没有任何运气...
我在文档中找到了这个:
array(
'conditions' => array('Model.field' => $thisValue), //array of conditions
'recursive' => 1, //int
'fields' => array('Model.field1', 'DISTINCT Model.field2'), //array of field names
'order' => array('Model.created', 'Model.field3 DESC'), //string or array defining order
'group' => array('Model.field'), //fields to GROUP BY
'limit' => n, //int
'page' => n, //int
'offset'=>n, //int
'callbacks' => true //other possible values are false, 'before', 'after'
)
有关数据库的其他信息:
项目有很多小时。小时属于项目。以小时为单位是 project_id。
CakePHP 2.1.2。
谢谢!:)