MYSQL-mysql5.7.5及以上版本將sql_mode的ONLY_FULL_GROUP_BY模式

當mysql5.7.5及以上版本將sql_mode的ONLY_FULL_GROUP_BY模式默認設置爲打開狀態,很多時候我們的sql會出現很多問題,如下:
1、我們使用GROUP BY查詢時,出現在SELECT字段後面的只能是GROUP BY後面的分組字段,或使用聚合函數包裹着的字段,否則會報錯如下信息:
  Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘database.table.column’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
2、當使用ORDER BY查詢時,不能使用SELECT DISTINCT去重查詢。否則會報錯如下信息:
Expression #1 of ORDER BY clause is not in SELECT list, references column ‘database.table.column’ which is not in SELECT list; this is incompatible with DISTINCT

由於我查詢的時候是線上數據庫,更換sql_mode會重啓數據庫,所以只能在邏輯中規避這些錯誤,不使用這些sql了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章