今天由mysql 5.6升級到5.7的時候,遇到一個group by的錯誤:
Expression #2 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘trade.create_time’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
原來,執行下面語句發現,默認的sql_mode修改了,變成: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_SUBSTITUTION,而5.6版默認是:NO_ENGINE_SUBSTITUTIONmysql
1sql |
|
沒辦法,須要去掉ONLY_FULL_GROUP_BY,則執行spa
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'
;
code