前言
在执行sql语句时候经常出现下面异常
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘imooc.s.type_name’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
ONLY_FUll_GROUP_BY 的意思是: 对于group by聚合操作,如果在select中的列,没有在Group by中出现,那么这个SQL是不合法的,因为列不在Gruop by 语句,也就是说查出来的列必须是GROUP BY之后的字段,或者这个字段出现在聚合函数里面。
解决办法
临时方法
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
永久sql_mode变更
找到 my.cnf
[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"
网友评论