MySQL Group By 出错

MySQL 查询出错

查询出错 (1055): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'rbac_auth_assignment.item_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

大概意思是 因为 MySQL 开启了 only_full_group_by 模式, 查询语句里面 SELECT 列出的字段 (除了集合类的 count sum ...) 必须在 GROUP BY 里面出现.

解决方法就是 修改 配置文件 或者是在 出错的语句前执行 下面的代码,临时改变 sql_mode

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

Post Author: admin