go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly

Home Page:https://gorm.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

GoldBaby5511 opened this issue · comments

你好,我的使用方式如下
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 的话在两种数据库上都是可以通过,这个要怎么处理
谢谢

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

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

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

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不行,是不是应该对不同数据库做个适配区分一下语法

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