mysql 1111,获得“#1111 - 组功能的无效使用”没有在MySQL中使用GROUP

$qb = $this->createQueryBuilder('t');

return $qb

->join('t.customers', 'c')

->where($qb->expr()->eq('t.user', $user->getId()))

->andWhere($qb->expr()->gt($qb->expr()->count('c'), 0))

->orderBy('t.name')->getQuery()->getResult();

The above query (Doctrine2 generated one) is giving me this error:

#1111 - Invalid use of group function

but the strange thing is i'm not using GROUP BY. Any help is much appreciated, thanks.

SELECT t0_.id AS id0,

t0_.slug AS slug1,

t0_.name AS name2,

t0_.description AS description3,

t0_.user_id AS user_id4

FROM tag t0_

INNER JOIN customers_tags c2_ ON t0_.id = c2_.tag_id

INNER JOIN customer c1_ ON c1_.id = c2_.customer_id

WHERE t0_.user_id = 1 AND COUNT(c1_.id) > 0

ORDER BY t0_.name ASC

解决方案

You are using an aggregate function count() in the where clause which is not allowed.

Conditions on aggregate functions need to go into a HAVING clause

....

WHERE t0_.user_id = 1

HAVING count(c1_.id) > 0

And of course you'll need to use a GROUP BY to get correct results (although MySQL will probably let you get away with not using a GROUP BY - but then the results are unpredictable)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值