MySQL:#1111-无效使用组函数;where条件查询中使用聚合函数报错
报错
SQL state [HY000]; error code [1111]; Invalid use of group function;
nested exception is java.sql.SQLException: Invalid use of group function] with root cause
解决方案
“where”是一个约束声明,在查询数据库的结果返回之前对数据库中的查询条件进行约束,即在结果返回之前起作用,且“where”后面不能写“聚合函数”。
“having”是一个过滤声明,是在查询数据库结果返回之后进行过滤,即在结果返回值后起作用,并且“having”后面可以写“聚合函数”。
where、聚合函数、having在from后面的执行顺序:
where>聚合函数(sum,min,max,avg,count)>having
where后面不能跟聚合函数,要想使用聚合函数作为条件查询,可以使用having
参考:https://blog.csdn.net/qq_41587243/article/details/83022883