Mysql

关注公众号 jb51net

关闭
首页 > 数据库 > Mysql > sql_mode=only_full_group_by

mysql报错sql_mode=only_full_group_by解决

作者:朱永胜

这篇文章主要为大家介绍了mysql报错sql_mode=only_full_group_by解决,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

报错内容

### The error may exist in file[D:\code\cppCode20221025\leader-system\target\classes\mapper\system\TJsonDataMapper.xml]
        ### The error may involve defaultParameterMap
        ### The error occurred while setting parameters
        ### SQL:select ifnull(s.type,'')type,ifnull(GROUP_CONCAT(s.yjzbname,':',s.num),'0')nums from(select t.type,(select name from t_norm s where s.id=n.parentId)yjzbname,count(*)num from t_org_ticket o left join t_ticket t on t.id=o.ticket_id and t.project_id=?left join t_norm n on n.model=t.modelid and n.project_id=?where o.org_id=?and t.type=?and n.type='02'GROUP BY parentId)s
        ### Cause:java.sql.SQLSyntaxErrorException:In aggregated query without GROUP BY,expression #1of SELECT list contains nonaggregated column's.type';this is incompatible with sql_mode=only_full_group_by
        ;bad SQL grammar[];nested exception is java.sql.SQLSyntaxErrorException:In aggregated query without GROUP BY,expression #1of SELECT list contains nonaggregated column's.type';this is incompatible with sql_mode=only_full_group_by

如何解决

调整GROUP BY子句和SELECT列表:

保证查询的字段在group by中即可

禁用only_full_group_by模式:

如果你确定查询的逻辑和数据不会引起问题,可以在查询之前执行以下命令来临时禁用only_full_group_by模式:

SET SESSION sql_mode='';

这可能会导致一些数据不一致性问题,只有在你非常确定情况下才应该使用。

如果是需要永久写入,那就需要写到cnf或ini配置中

mysql中配置文件地址一般是`C:\Program Files\MySQL\MySQL Server 5.7\bin\my.ini

我的在这里额

查询已经有的sql_mode

select @@sql_mode

在ini中添加查询出来的模式配置,然后去掉only_full_group_by模式即可

[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

重新设计查询:

如果无法简单地调整GROUP

-->BY子句和SELECT列表,你可能需要重新设计查询逻辑。这可能涉及到使用子查询、临时表或其他方式来满足only_full_group_by模式的要求。 。

以上就是mysql报错sql_mode=only_full_group_by解决的详细内容,更多关于sql_mode=only_full_group_by的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文