MYSQL---Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column

--數據庫中插入數據或執行sql語句時一直報下面這個錯誤:
Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' 
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

 

緣由:這是數據庫的sql_mode設置的有問題。Mysql能夠支持不一樣的SQL模式,不一樣的SQL模式會有不一樣的語法,執行不一樣的數據校驗簡查。sql

首先,能夠先查看一下數據庫如今的sql_mode的值,sql語句爲:數據庫

select version(), @@sql_mode;this

獲取結果可能以下,不一樣的設置查詢出來的有區別:spa

 

而後能夠使用以下語句,去設置本身須要的sql_mode..net

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

code

2、嘗試第二種方案orm

一、查看sql_modeblog

select @@sql_mode
查詢出來的值爲:it

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONio

二、去掉ONLY_FULL_GROUP_BY,從新設置值。

set @@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,對於新建的數據庫有效。對於已存在的數據庫,則須要在對應的數據下執行:

set sql_mode =‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION‘;或者:在my.cnf 裏面設置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 中去掉only_full_group_by 傳送門:https://blog.csdn.net/u012259256/article/details/56482218

相關文章
相關標籤/搜索