簡體   English   中英

CakePHP 3.6:從表中計算不同的記錄

[英]CakePHP 3.6: Count distinct records from table

我試圖在具有 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 Distinct不起作用。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM