开发者

How to use having on un-aggregate field in MySQL?

开发者 https://www.devze.com 2023-01-16 03:20 出处:网络
select xx as fieldA from ... group by xxx having fieldA is not null 开发者_Go百科 I found that having has no effectMay be :
select xx as fieldA from ... group by xxx having fieldA is not null
开发者_Go百科

I found that having has no effect


May be :

 select xx as fieldA from ... where fieldA is not null group by xxx having 

help you


You should include all non-aggregate columns in the GROUP BY. 5.7.5 introduced the SQL_MODE of only_full_group_by to enforce such (while not complaining about some cases where it is actually OK).

When you have a non-aggregate column, the code is free to provide any value it likes for such a column (xx in your case). Given that, then how could the HAVING make any rational sense.

This is not a bug; it is a user error.

0

精彩评论

暂无评论...
验证码 换一张
取 消