![](/img/trans.png)
[英]how to select all records from one table and some from another table in 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.