mysql - 错误代码 : 1111. 群组功能使用无效

标签 mysql

select max(postal_code) from address
where max(postal_code) 
IN (select Min(postal_code) from address
group by district
having  min(postal_code) <> "" and district <> "" );

谁能告诉我为什么会出现这个错误?

最佳答案

错误在下一行。除了 HAVING 子句

之外,您不能在 WHERE 子句中使用组函数
where max(postal_code) 

您可以尝试像下面这样修改您的查询

select max_postalcode 
from 
(
select max(postal_code) as max_postalcode,
Min(postal_code) as min_postal_code 
from address
where district is not null
group by district
having  min(postal_code) is not null
) xxx 
where max_postalcode = min_postal_code;

关于mysql - 错误代码 : 1111. 群组功能使用无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32268863/

相关文章:

php - 添加到数据库时出现奇怪的 mySQL 错误

mysql - sql文件导入MySQL数据库时出错

sql - MySQL 中的记录可见但不可访问 - 为什么?

php - 当不需要排序时首选哪种排序规则?

mysql - mysql delete 语法与 select 有何不同?

mysql - 如何在一个 SQL 查询中选择同一个表中的相关项

python - 如何使用python向mysql数据库插入变量? "You have an error in your SQL syntax"

mysql - 如何在 MySql 查询中执行此操作?

javascript - 关于node.js中的MySQL模块以及与mySQL数据库的并发连接

python - 如何在Windows 7中使用Python 3.3.4在Django 1.5.5中运行mysql