錯誤
報錯如下:
Error querying database. Cause: : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression
#2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'temp.applyinstId' which is not functionally
dependent on columns in GROUP BY clause;
this is incompatible with sql_mode=only_full_group_by
重點是:
this is incompatible with sql_mode=only_full_group_by
原因
這個錯誤是mysql 5.7 版本及以上版本會出現的問題:
- mysql 5.7版本預設的sql配置是:sql_mode=“ONLY_FULL_GROUP_BY”,這個配置嚴格執行了"SQL92标準"。
在sql執行時:
- 輸出的結果是叫target list,就是select後面跟着的字段,還有一個地方group by column,就是 group by後面跟着的字段。由于開啟
ONLY_FULL_GROUP_BY
的設定,是以如果一個字段沒有在target list 和group by字段中同時出現,或者是聚合函數的值的話,那麼這條sql查詢是被mysql認為非法的,會報錯誤。
解決
1、臨時
修改sql_mode:
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
但是這種方式每次重新開機,sql_mode又會初始化。
2、徹底
修改mysql配置檔案my.ini:
在 [mysqld]下添加:
sql_mode =STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION;
參考:
【1】:
https://blog.csdn.net/qq_42175986/article/details/82384160【2】:
https://www.cnblogs.com/jim2016/p/6322703.html【3】:
https://blog.csdn.net/sinat_40770656/article/details/101198274【4】:
https://blog.csdn.net/liuyongyuan2012/article/details/81946388