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

sql server中使用Count函数报语法错误 #7087

Open
GoldBaby5511 opened this issue Jun 26, 2024 · 5 comments
Open

sql server中使用Count函数报语法错误 #7087

GoldBaby5511 opened this issue Jun 26, 2024 · 5 comments
Assignees
Labels

Comments

@GoldBaby5511
Copy link

你好,我的使用方式如下
err = e.Orm.Debug().Model(&data).
Scopes(
cDto.MakeCondition(c.GetNeedSearch()),
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
actions.Permission(data.TableName(), p),
).
Find(list).Limit(-1).Offset(-1).
Count(count).Error
if err != nil {
e.Log.Errorf("Service GetSysApiPage error:%s", err)
return err
}
在最后统计Count时最终的执行语句是:SELECT count(*) FROM "sys_api" WHERE "sys_api"."deleted_at" IS NULL ORDER BY "id"
这在mysql上是可以执行通过的,但是在sql server上报错:“ORDER BY 子句中的列 "sys_api.id" 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。”,如果没有 ORDER BY 的话在两种数据库上都是可以通过,这个要怎么处理
谢谢

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Jun 26, 2024
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@Cirooo
Copy link

Cirooo commented Jun 26, 2024

gorm不会无端加入这个order字句,你应该检查自己的调用链。

Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@GoldBaby5511
Copy link
Author

gorm不会无端加入这个order字句,你应该检查自己的调用链。

我对gorm还不是很熟悉,order字段可能是 Limit(-1).Offset(-1) 内加入的,关键是最终的sql语句 SELECT count(*) FROM "sys_api" WHERE "sys_api"."deleted_at" IS NULL ORDER BY "id" mysql下是可以执行的,mssql不行,是不是应该对不同数据库做个适配区分一下语法

Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

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

No branches or pull requests

3 participants