MySQL sql_mode=only_full_group_by异常解决

作者:じ☆ve宝贝

发布时间:2016-06-20T09:31:46

MySQL 5.7以上版本,如果使用group by 去重可能会出现 this is incompatible with sql_mode=only_full_group_by,其实是如果有些值并非一行,不会默认取第一行,因此会发生此异常!

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Expression #1 of SELECT list is not in GROUP BY clause and contains  nonaggregated column 'test.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by  

解决办法:

SELECT any_value(p.id) id,any_value(p.name) NAME,…… FROM wm_plate p  GROUP BY ……