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了。

发布了261 篇原创文章 · 获赞 174 · 访问量 61万+

猜你喜欢

转载自blog.csdn.net/u013047824/article/details/105146910