Php 条令-按id统计表中的用户数
我在数据库中有6条记录。 3来自用户1,2来自用户2,1来自用户3 我想按用户id对它们进行计数,这样最终结果将是3。它总是返回表中所有记录的计数。它返回6 我的职责:Php 条令-按id统计表中的用户数,php,symfony,doctrine-orm,query-builder,Php,Symfony,Doctrine Orm,Query Builder,我在数据库中有6条记录。 3来自用户1,2来自用户2,1来自用户3 我想按用户id对它们进行计数,这样最终结果将是3。它总是返回表中所有记录的计数。它返回6 我的职责: return $this->getDeviceRepository() ->createQueryBuilder('tlu') ->select('COUNT(tlu.user_id)') ->getQuery() ->getResul
return $this->getDeviceRepository()
->createQueryBuilder('tlu')
->select('COUNT(tlu.user_id)')
->getQuery()
->getResult();
您有两种解决方案(使用groupBy或countDistinct)
或
您有两种解决方案(使用groupBy或countDistinct)
或
是的,我们可以这样做
getResult()->count();
或
是的,我们可以这样做
getResult()->count();
或
这回答了你的问题吗?这回答了你的问题吗?我需要在结果上添加count($result),因为它返回包含3个对象的数组@RachedBCHI需要在结果上添加count($result),因为它返回包含3个对象的数组@拉赫德伯奇
getResult()->count();
return $this->getDeviceRepository()
->createQueryBuilder('tlu')
->select('COUNT(tlu.user_id)')
->countDistinct('tlu.user_id')
->getQuery()
->getSingleScalarResult();