#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'benxi.benxi_minute_data.name_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
今天用了一个mysql语句:
SELECT name_id,zhi FROM `lmcjl` group by name_id
然后就报这个错误:
#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'benxi.benxi_minute_data.name_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这个错误发生在mysql 5.7.5 和以后上,因为5.7.5默认的sql模式配置是ONLY_FULL_GROUP_BY
这个配置启用的是 “严格ANSIsql 规则”,严格ANSI sql 规则要求在group by的时候,没有聚合的列,在group by的时候,必须全部包含在group by 的字段中。
最后的解决方法:
SELECT name_id,sum(zhi)zhi FROM `lmcjl` group by name_id
``
加个聚合就完美了