1055 Expression #1 of SELECT list is not in GROUP BY clause

mysql使用group by 报错:

Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX.Y.ZZZZ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决链接:
https://www.cnblogs.com/yangfei123/p/10178...

讨论数量: 1

@xcy
文中链接的解决方案实际上是错的,它仅仅是让SQL语句不报错了。 当出现文中的错误时,说明写的GROUP BY SQL语句有歧义,MySQL不知道取哪一个数据。MySQL5.7开始有only_full_group_by实际上是为了修复之前的bug。
如果是新项目,正确做法是修改写的GROUP BY SQL语句。

1周前 评论

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!