1

我想从数据库中获取记录数。

在我的表中,这是值:

id  emp_id  number  created_emp_id  status  timestamp
29  7   1   2   0   2012-09-24 15:18:28
30  16  1   2   0   2012-09-24 15:18:28
31  7   2   2   0   2012-09-24 15:18:54
32  19  2   2   0   2012-09-24 15:18:54

created_emp_id2

所以我需要她的结果是2。

这意味着这number是一个重复的列。

这是我为获得结果而编写的代码:

$result = $this->TravancoDSRGroup->find('all', array('conditions' => array('created_emp_id= '.$emp_id),'fields' => array('DISTINCT TravancoDSRGroup.number')));

仅返回两$result行。

但我需要得到这个查询的计数......

像...

$dsrPageCnt = $this->TravancoDSRGroup->find('count',................

我怎样才能做到这一点?

4

1 回答 1

3

你可以试试这个:

$dsrPageCnt = $this->TravancoDSRGroup->find('count', array('conditions' => array('created_emp_id= '.$emp_id),'fields' => array('DISTINCT TravancoDSRGroup.number')));

http://book.cakephp.org/1.3/view/1020/find-count

于 2012-09-24T10:45:57.527 回答