Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 1055: this is incompatible with sql_mode=only_full_group_by #12

Open
bay1 opened this issue Aug 6, 2018 · 2 comments
Open

Error 1055: this is incompatible with sql_mode=only_full_group_by #12

bay1 opened this issue Aug 6, 2018 · 2 comments

Comments

@bay1
Copy link

bay1 commented Aug 6, 2018

问题:

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 bay1 changed the title 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 Error 1055: this is incompatible with sql_mode=only_full_group_by Aug 7, 2018
@TruthHun
Copy link
Owner

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

@bay1
Copy link
Author

bay1 commented Aug 14, 2018

嗯,按照您的需求,我通过禁用 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants