not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
时间: 2023-02-13 09:58:04 浏览: 55
这是 MySQL 的一个错误消息,意思是你的 SQL 语句中的某个列在 `GROUP BY` 子句中不是功能依赖的,这和 `sql_mode=only_full_group_by` 不兼容。
这个错误通常是由于你的 SQL 语句中使用了 `SELECT` 子句中的某些列,但没有在 `GROUP BY` 子句中明确指定这些列。为了避免这种错误,你应该在 `GROUP BY` 子句中指定所有在 `SELECT` 子句中使用的列,或者禁用 `only_full_group_by` 模式。
例如,下面的 SQL 语句会导致这个错误:
```
SELECT col1, col2
FROM table
GROUP BY col1;
```
因为在 `SELECT` 子句中使用了 `col2`,但没有在 `GROUP BY` 子句中指定。为了避免这种错误,应该改为:
```
SELECT col1, col2
FROM table
GROUP BY col1, col2;
```
相关问题
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这个错误是MySQL数据库在使用ONLY_FULL_GROUP_BY模式时出现的。这种模式要求在GROUP BY子句中的每个列都必须是聚合函数或GROUP BY子句中的列。如果SELECT列表中的列不在GROUP BY子句中,也不是聚合函数,则会出现“which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”错误。解决此问题的方法是将sql_mode设置为非ONLY_FULL_GROUP_BY模式,或者将SELECT列表中的列添加到GROUP BY子句中。以下是两种解决方法:
1.将sql_mode设置为非ONLY_FULL_GROUP_BY模式
```sql
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
```
2.将SELECT列表中的列添加到GROUP BY子句中
```sql
SELECT t1.id, t2.name, COUNT(*)
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id
GROUP BY t1.id, t2.name;
```
functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
这个错误是由于MySQL的sql_mode设置为only_full_group_by导致的。在MySQL 5.7.5之后,sql_mode默认启用了ONLY_FULL_GROUP_BY模式,它要求GROUP BY子句中的每个列都必须是聚合函数或GROUP BY子句中的列。如果SELECT列表中包含GROUP BY子句中未列出的列,则会出现“not functionally dependent on columns in GROUP BY clause”错误。解决此问题的方法是将sql_mode设置为非ONLY_FULL_GROUP_BY模式,或者将SELECT列表中的列添加到GROUP BY子句中。以下是两种解决方法:
1.将sql_mode设置为非ONLY_FULL_GROUP_BY模式
```sql
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
```
2.将SELECT列表中的列添加到GROUP BY子句中
```sql
SELECT id AS id,uid,rid FROM sys_user_role WHERE (rid = '1259293401992036353') GROUP BY uid, id;
```