mysql group by 過濾字段 只能在SELECT 后面出現,不能寫其他字段 報錯解決 關鍵字 sql_mode=only_full_group_by


1:報錯  關鍵字 sql_mode=only_full_group_by
mysql> select uuid,ip,count(*) from dbname_report.t_client_ips group by uuid limit 1;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dbname_report.t_client_ips.ip' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

2:查看模式
mysql> select @@global.sql_mode
-> ;
+------------------------------------------------------------------------------------------------------------------------+
| @@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 |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

3:設置模式

mysql> set @@global.sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
-> ;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> select uuid,ip,count(*) from dbname_report.t_client_ips group by uuid limit 1;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dbname_report.t_client_ips.ip' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
mysql> select @@global.sql_mode;

4:查看
+--------------------------------------------+
| @@global.sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)

5:執行還是報錯

6:修改數據庫配置文件

cat /etc/my.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

7:重啟數據庫,可以解決


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM