CakePHP SQL Where Count IS

时间:2014-02-02 22:26:13

标签: sql cakephp

在CakePHP中我试图这样做,以便我可以计算有多少个实例(在这种情况下是searchterm),如果有超过10个实例,我只能选择该术语。

我试过这个:

 $results = $this->Search->find('all',
            array('fields' => array('Search.searchterm'),

                'conditions' => array(


                    array('Search.searchterm LIKE' =>  $this->request->query['term'] . '%'),
                    array('count(Search.searchterm)' => '10'),

              ),

                'group' => array('Search.searchterm'),
                'limit' => 15,

    ));

所以在这个例子中,我试图选择所有搜索条件,其中有10个实例,但我无法让它工作。

有可能吗?

1 个答案:

答案 0 :(得分:0)

改为find('count')

$results = $this->Search->find('count',
    'conditions' => array(
        array('Search.searchterm LIKE' =>  $this->request->query['term'] . '%'),
    ),
));

And read the manual about the finds