使用联表查询时,group by两个字段出现了错误
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'train_c.e.ques_type' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
意思是select字段里包含了没有被group by 条件唯一确定的字段。
MySQL版本5.7之后会检测函数依赖,默认启用的模式是ONLY_FULL_GROUP_BY,使用GROUP BY 语句违背了sql_mode=only_full_group_by。该模式的意思是只有确定唯一字段的group by才能执行。
使用SQL查询sql_mode
select @@global.sql_mode
在MySQL-server层面修改sql_mode,在配置文件my.cnf中关闭sql_mode=ONLY_FULL_GROUP_BY
,将sql_mode配置放在 [mysqld] 后
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
重启mysqld服务
systemctl restart mysqld.service systemctl start mysqld.service systemctl stop mysqld.service
成功
上一篇:MySQL综合练习题