报错提示:
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hl.c.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
报错原因:
由于mysql版本不同导致。以下均为个人看法。
mysql 5.x版本之前支持 select a,b from table_name group by a;
mysql 8.x版本进行优化,group by语法进行了修改。按某个字段分组,就只能查询到某个字段。
select a from table_name group by a;
select a,b from table_name group by a,b;
解决方式:
1.修改代码:将代码改成符合语法的sql语句。
select a,b from table_name group by a,b;
2.修改数据库设置【仅仅推荐测试库使用】
a.查询sql模式
select @@global.sql_mode;
b.修改sql模式
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
c.退出重新登录
#退出
quit;
# 再次登录(命令行模式)
mysql -u 用户名 -p 密码;