1. 程式人生 > 資料庫 >In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column &#0

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column &#0

錯誤:

In aggregated query without GROUP BY, expression #3 of SELECT list contains nonaggregated column 'emsdb_pro.mainspareparts.CreationTime'; this is incompatible with sql_mode=only_full_group_by

 

原因是:當mysql的sql_mode存在only_full_group_by的時候,在不使用group by 並且select後面出現聚集函式的話,那麼所有被select的都應該是聚集函式,否則就會報錯。

 

解決:

在mysql 的配置檔案(my.ini)中修改

注意:要將sql_mode配置放置在[mysqld]節下面

 

 

 儲存檔案後使用命令列重啟資料庫:

net stop mysql

net start mysql

 

 

執行之後到資料庫中執行

set @@global.sql_mode = `STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION`;

在使用select @@global.sql_mode查詢

結果中就不存在

ONLY_FULL_GROUP_BY