mysql group_by 的问题

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'DBname.table.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by


平台: Mac OS X
报错: incompatible with sql_mode=only_full_group_by
版本: mysql  Ver 14.14 Distrib 5.7.16, for osx10.11 (x86_64) using  EditLine wrapper
参考: https://stackoverflow.com/questions/23921117/disable-only-full-group-by 
搜索: "version 5.7.11 running on Mac OS X"


解决办法:
1)命令行登录mysql
2)执行语句:

SET @@GLOBAL.sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

设置好之后没有重启就可以;重启可能导致配置消失;

3)搞定

==================== 成功案例 ======================
mysql> select t.id from transactions t,transaction_info i where t.id=i.t_id   group by i.email order by i.email ASC;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'DBname.table.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
 
 
mysql> SET @@GLOBAL.sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
Query OK, 0 rows affected (0.01 sec)
 
 
mysql> select t.id from transactions t,transaction_info i where t.id=i.t_id   group by i.email order by i.email ASC;
+-------+
| id    |
+-------+
|   436 |
|  7425 |
|  9372 |

--------------------- 
作者:Rudon滨海渔村 
来源:CSDN 
原文:https://blog.csdn.net/qq285744011/article/details/73087822 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/weixin_38859557/article/details/88667271