SELECT list is not in GROUP BY clause and contains nonaggregated column 't_user_rel.distance' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=on


错误信息

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 
 't_user_rel.distance' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
 
SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column
 't_team.uid'; this is incompatible with sql_mode=only_full_group_by

 

发生错误的源sql语句

SELECT `uid`,`distance` FROM `t_user_rel` WHERE  `uid` IN (7534,2967,2145,901,746,654,2) GROUP BY `uid` ORDER BY distance asc"

其中distance 不是group by的字段 ,数据库做了限制 sql_mode = only_full_group_by,所以报错

解决方法

错误信息就是sql语句使用group by的时候 获取字段column 不是分组的字段,mysql配置做了限制: sql_mode=only_full_group_by

网上查了很多的解决方法就是修改配置文件,就可以解决这个问题。

参考:https://blog.csdn.net/qq_42175986/article/details/82384160

解决方法就是把

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

设置成

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

就是把分组查询字段不做限制

查看数据库sql_mode的配置

SHOW VARIABLES LIKE '%sql_mode%'

yum指定官方源安装好的不同mysql版本的默认sql_mode 的配置如下:
MySQL5.7.24

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 

MySQL5.7.25

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

MySQL5.7.26

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

由上可以得出5.7.26以及之后的版本ONLY_FULL_GROUP_BY 是官方默认的配置


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by问题分析 [mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'loser.tank_admin.login_ip' which is not functionally dependent on columns in GROUP BY clause; this is 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this 数据库多表连接查询中使用group by分组语句,Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in GROUP BY claus mysql 执行报错:Error querying database. Cause: java.sql.SQLSyntaxErrorException:which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT list is not in GROUP BY clause and contains nonaggregated column mysql出现which is not functionally dependent on columns in GROUP BY clause报错 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo. MySQL: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM