only_full_group_by报错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了only_full_group_by报错相关的知识,希望对你有一定的参考价值。
参考技术A 报错了:### Cause: java.sql.SQLSyntaxErrorException: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'xxxxxxx'; 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 #2 of SELECT list contains nonaggregated column 'xxxxxx'; this is incompatible with sql_mode=only_full_group_by
原因是:在调用count(*)聚合方法时, 增加了排序字段,而shardingsphere默认会分表查询前,将聚合排序字段,拼接到count后:
所以去掉排序就好了。
mysql升级到8后报错,only_full_group_by报错
【中文标题】mysql升级到8后报错,only_full_group_by报错【英文标题】:Mysql error after upgrade to 8, only_full_group_by error 【发布时间】:2018-12-30 03:36:02 【问题描述】:这行给了我错误:
错误:SELECT 列表的表达式 #1 不在 GROUP BY 子句中,并且 包含非聚合列“hng_1.tags.id”,它不是 功能上依赖于 GROUP BY 子句中的列;这是 与 sql_mode=only_full_group_by 不兼容
foreach($groups as $group)
$query = mysqli_query($verbindung, "SELECT * FROM (SELECT *, COUNT(id) AS c FROM tags WHERE typ='" . mysqli_real_escape_string($verbindung, $group) . "' GROUP BY slug ORDER BY c DESC LIMIT 9) AS i ORDER BY i.tag ASC") or die("Error: " . mysqli_error($verbindung));
while ($row = mysqli_fetch_array($query))
$tmp_tags[] = $row;
如何更改查询以修复此错误?
【问题讨论】:
您的查询毫无意义。也许向我们展示您的预期输出是什么,我们可以为您提供帮助。很高兴看到新的 MySQL 8 only full group by message 更好地解释了正在发生的事情。 您希望查询做什么?这包括给出对输入的约束以及输出如何成为输入的函数。你以为老头子做了什么?您是否通过文档阅读了该组以了解它的实际作用?请阅读minimal reproducible example并采取行动。 了解如何操作GROUP BY
。您的查询无效,这就是它崩溃的原因。
【参考方案1】:
对于其他感兴趣的人,我解决了这个问题。我将 id 添加到 GROUP BY,所以它现在知道要选择什么。
GROUP BY slug, id
修复它。
【讨论】:
以上是关于only_full_group_by报错的主要内容,如果未能解决你的问题,请参考以下文章
mysql升级到8后报错,only_full_group_by报错
MySQL报错:sql_mode=only_full_group_by 4种解决方法含举例,轻松解决ONLY_FULL_GROUP_BY的报错问题