我正在尝试使用以下命令在我的数据库上使用 Doctrine2 运行自定义查询:
$qb = $em->createQueryBuilder();
$qb->select(array('c', 'count(uc) as numMembers'))
->from('AcmeGroupBundle:Group', 'c')
->leftJoin('c.members', 'uc', 'WITH', 'uc.community = c.id')
->groupBy('c')
->orderBy('numMembers', 'DESC')
->setFirstResult( $offset )
->setMaxResults( $limit );
$entities = $qb->getQuery()->getResult();
此查询在我的本地 MySQL 数据库上完美运行。但是当我尝试对我的生产数据库(MSSQL)运行它时,我收到以下错误:
SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Column 'Group.discr' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
我确实有一个鉴别器列,因为我有从 Group 继承的类。关于如何更改查询以使其与 MSSQL 兼容的任何建议?
谢谢!