针对MSSQL运行GROUP BY的Doctrine2问题

时间:2013-04-24 09:10:19

标签: sql-server doctrine-orm

我正在尝试使用以下内容在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兼容的任何建议?

谢谢!

0 个答案:

没有答案