php - CakePHP 3.6:计算表中不同的记录
问题描述
我正在尝试在具有 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();
推荐阅读
- java - removeAt java arraylist android出错
- c++ - C++ 控制台应用程序调用 C++/CLI 静态库
- elasticsearch - 在搜索唯一 ID 时,它给出了多个计数
- amazon-web-services - 通过 AWS CLI 中的 aws ssm 启动会话记录后传递命令
- jquery - Jquery 音频位置控制
- linux - 用于查找机器人元标记值的 Bash shell 脚本
- c++ - 在 C++ 中使用 istringstream 读取输入时出错
- mysql - 按特定条件订购商品,然后是其余商品
- ios - 线程 1:EXC_BAD_ACCESS(代码=2,地址=0x16d0f3ff0)
- latex - 使用 \bibentry 显示内联引文前面的数字