DISTINCT关键字经常在MySQL中使用,在mysql5.7以前的版本中一般没有什么问题,但是在5.7以后的版本中会遇到这样的错误
Caused by: java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list, references column ‘game.giftbag0_.create_date’ which is not in SELECT list; this is incompatible with DISTINCT
错误提示DISTINCT不兼容,要么更改SQL,但是对于开发者来讲,sql运行一直都是正常的,可能是mysql 版本升级导致的安全问题,5.7.x安全性提升了很多,解决办法可以考虑修改MySQL配置文件,找到对应的my.cnf或者my.ini
- sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
添加该行就ok!
还有一种错也是不兼容的问题导致的
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘nctest.pivot.id’ 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导致的,去掉only_full_group_by就解决了
没有评论