only_full_group_by报错

报错了:

### Cause: java.sql.SQLSyntaxErrorException: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'xxxxxxx'; this is incompatible with sql_mode=only_full_group_by

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'xxxxxx'; this is incompatible with sql_mode=only_full_group_by


原因是:在调用count(*)聚合方法时, 增加了排序字段,而shardingsphere默认会分表查询前,将聚合排序字段,拼接到count后:

SELECT COUNT( 1 ) , create_time AS ORDER_BY_DERIVED_0 FROM xxxxxx_2022

  ORDER BY create_time DESC

所以去掉排序就好了。

你可能感兴趣的:(only_full_group_by报错)