CAKEPHP3.6:从表中统计不同的记录

CAKEPHP3.6:从表中统计不同的记录,php,cakephp,count,distinct,Php,Cakephp,Count,Distinct,我试图在具有where条件的表上实现不同的计数 这就是我尝试过的: $customerServiceTypes = TableRegistry::get('CustomerServiceTypes'); $customers_count = $customerServiceTypes->find('all', array( 'fields' => 'DISTINCT CustomerServiceType.customer_id', '

我试图在具有where条件的表上实现不同的计数

这就是我尝试过的:

$customerServiceTypes = TableRegistry::get('CustomerServiceTypes');
$customers_count = $customerServiceTypes->find('all', array(
            'fields' => 'DISTINCT CustomerServiceType.customer_id',
            'conditions' => array("CustomerServiceTypes.service_type_id" => $id)))->count();
但它不起作用。我得到的结果是
25
,但应该是
2
<代码>独立不工作

$customerServiceTypes = TableRegistry::get('CustomerServiceTypes');
$customers_count = $customerServiceTypes->find()
     ->select(['customer_id'])
     ->distinct()
     ->where(['service_type_id =' => $id])->count();