草庐IT

mysql - 语法错误或访问冲突 : 1055 Expression #8 of SELECT list is not in GROUP BY clause and contains nonaggregated column

coder 2023-06-11 原文

我尝试了 CakePHP 3.x “Bookmaker 教程”,并按照说明一步一步地进行操作。不幸的是,在第一章结束时,我收到了附加错误:

Error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #8 of SELECT list
is not in GROUP BY clause and contains nonaggregated column 'wis.Tags.id' which is not
functionally dependent on columns in GROUP BY clause; this is incompatible with 
sql_mode=only_full_group_by

此外,我得到了检查我的“BookmarksTags”表的信息,但我之前不必创建一个。我有点困惑。

Please try correcting the issue for the following table aliases:

BookmarksTags

我已经用谷歌搜索了我的问题,并找到了用额外的行更新“my.cnf”的信息。我已经尝试过了,但什么也没发生。我还检查了拼写并从 github 下载了“bookmarker-tutorial”,但上面仍然出现此错误。

我使用 MySQL 5.7.11 和 PHP 5.6.14。

最佳答案

这是 MySQL 5.7 中的新事物,警告您的查询不明确。

考虑下表:

id    |   name    |   age    |   points
--------------------------------------------
1         Bob         21         1
2         James       14         1
3         Bob         21         3
4         James       14         2
5         Casey       17         3

如果您执行了以下查询:

SELECT name, age, SUM(points) FROM scores GROUP BY name

然后 name 列用于分组。请注意,age 可能有多个值,因此它是“非聚合的”。您需要做一些事情来降低这些值。

在 5.6 和之前的版本中,行为只是根据排序顺序选择第一个,尽管这有时是不可预测的并且会失败。在 5.7 中,他们从一开始就阻止你这样做。

这里的解决方案是对其进行分组,或者对其应用聚合运算符,如 MIN()

关于mysql - 语法错误或访问冲突 : 1055 Expression #8 of SELECT list is not in GROUP BY clause and contains nonaggregated column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36228836/

有关mysql - 语法错误或访问冲突 : 1055 Expression #8 of SELECT list is not in GROUP BY clause and contains nonaggregated column的更多相关文章

随机推荐