DocHub icon indicating copy to clipboard operation
DocHub copied to clipboard

Error 1055: this is incompatible with sql_mode=only_full_group_by

Open bay1 opened this issue 7 years ago • 2 comments

问题:

Error 1055: Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'wenku.i.Id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

介绍 我的mysql: Ver 14.14 Distrib 5.7.18 修复建议:

  1. models/DocumentModel.go 155行,添加 "d.Id"
where %v group by d.Title, d.Id order by di.%v desc limit %v
  1. models/Models.go 416行,添加 "d.Title"
if sql, err := LeftJoinSqlBuild(tables, on, map[string][]string{"i": []string{"Count"}}, 1, 100000000, nil, []string{"i.DsId", "d.Title"}, cond); err == nil {

3.models/Models.go 431行,添加, "i.Score", "i.TimeCreate", "i.Id"

if sql, err := LeftJoinSqlBuild(tables, on, fields, p, listRows, orderBy, []string{"i.DsId", "i.Score", "i.TimeCreate", "i.Id"}, cond); err == nil {

bay1 avatar Aug 06 '18 16:08 bay1

group by d.Title是为了避免出现相同标题的文档在列表中显示,如果变为group by d.Title,d.Id,效果等同于不要group by的查询了,因为d.Id表示的是文档的主键Id,无论如何这个都不会出现重复的情况。 关于这个报错的问题,stackoverflow的解决方案: https://stackoverflow.com/questions/23921117/disable-only-full-group-by

TruthHun avatar Aug 14 '18 13:08 TruthHun

嗯,按照您的需求,我通过禁用 only_full_group_by 设置比较好~~

mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

https://stackoverflow.com/questions/34115174/error-related-to-only-full-group-by-when-executing-a-query-in-mysql

bay1 avatar Aug 14 '18 15:08 bay1