在mysql中无效使用组

时间:2014-12-08 04:37:55

标签: mysql sql doctrine-orm

我有以下查询:

return $this->createQueryBuilder('s')
                ->select('DISTINCT s.username') 
                ->addSelect('COUNT(p.id) as HIDDEN c_id')
                ->leftJoin('s.owner', 'o')
                ->leftJoin('s.userPictures', 'p')
                ->leftJoin('o.transactions', 't')
                ->leftJoin('t.packType', 'pt')
                ->where('pt.id =:packId')
                ->setParameter('packId', $packId)
                ->andWhere('s.expirydate >=:expiryDate')
                ->setParameter('expiryDate', new \DateTime('now'))
                ->andWhere('COUNT(p.id) <:numberOfPictures')
                ->setParameter('numberOfPictures', $numberOfPictures)
                ->groupBy('p.shop')
                ->orderBy("c_id", 'ASC')
                ->getQuery()
                ->getResult()
                ;

但是在尝试运行时,我总是无效地使用组功能。这是为什么?

以下是翻译时的真实SQL查询:

SELECT DISTINCT s.username, COUNT(p.id) as HIDDEN c_id 
FROM App\MainBundle\Entity\InstagramShop s 
    LEFT JOIN s.owner o 
    LEFT JOIN s.userPictures p 
    LEFT JOIN o.transactions t 
    LEFT JOIN t.packType pt 
WHERE pt.id =:packId AND s.expirydate >=:expiryDate AND COUNT(p.id) <:numberOfPictures 
GROUP BY p.shop 
ORDER BY c_id ASC

0 个答案:

没有答案