GroupBy 和 FindAndCount 一起使用的一个问题 #1726

Closed
opened 2020-06-27 07:49:28 +00:00 by 344085057 · 4 comments

go code:

ss := utils.GetEngine().Table("lc_model").Alias("a").
		Join("left", []string{"sys_cont", "b"}, " a.sys_cont_id = b.id").
		Where("a.company_id = ?", t.CompanyId).
		GroupBy("a.name,a.code,b.name,a.sys_cont_id")


	count, err := ss.
		Limit(paging.PageSize, (paging.Current-1)*paging.PageSize).
		FindAndCount(&lcModelListJoin)

产生的sql

SELECT TOP 10 [a].[name],[a].[code],[b].[name],[a].[sys_cont_id] FROM [lc_model] AS [a]
left JOIN [sys_cont] AS [b] ON a.sys_cont_id = b.id
WHERE (a.company_id = 33)
GROUP BY a.name,a.code,b.name,a.sys_cont_id


SELECT count(*) FROM [lc_model] AS [a]
left JOIN [sys_cont] AS [b] ON a.sys_cont_id = b.id
WHERE (a.company_id = 33)
GROUP BY a.name,a.code,b.name,a.sys_cont_id
go code: ```golang ss := utils.GetEngine().Table("lc_model").Alias("a"). Join("left", []string{"sys_cont", "b"}, " a.sys_cont_id = b.id"). Where("a.company_id = ?", t.CompanyId). GroupBy("a.name,a.code,b.name,a.sys_cont_id") count, err := ss. Limit(paging.PageSize, (paging.Current-1)*paging.PageSize). FindAndCount(&lcModelListJoin) ``` 产生的sql ```sql SELECT TOP 10 [a].[name],[a].[code],[b].[name],[a].[sys_cont_id] FROM [lc_model] AS [a] left JOIN [sys_cont] AS [b] ON a.sys_cont_id = b.id WHERE (a.company_id = 33) GROUP BY a.name,a.code,b.name,a.sys_cont_id SELECT count(*) FROM [lc_model] AS [a] left JOIN [sys_cont] AS [b] ON a.sys_cont_id = b.id WHERE (a.company_id = 33) GROUP BY a.name,a.code,b.name,a.sys_cont_id ```
Author

v1.0.2
sql server

v1.0.2 sql server

貌似不能一起用,还不知道怎么解决

貌似不能一起用,还不知道怎么解决

[xorm] [info]  2020/10/14 10:11:26.871319 [SQL] SELECT name, count(*) as cnt FROM `tbl_client_account` GROUP BY name ORDER BY `cnt` DESC LIMIT 10 [] - 493.453µs
[xorm] [info]  2020/10/14 10:11:26.872088 [SQL] SELECT count(*) FROM `tbl_client_account` GROUP BY name [] - 436.554µs
![](https://s1.ax1x.com/2020/10/19/0vXMAe.jpg) [xorm] [info] 2020/10/14 10:11:26.871319 [SQL] SELECT name, count(*) as cnt FROM `tbl_client_account` GROUP BY name ORDER BY `cnt` DESC LIMIT 10 [] - 493.453µs [xorm] [info] 2020/10/14 10:11:26.872088 [SQL] SELECT count(*) FROM `tbl_client_account` GROUP BY name [] - 436.554µs
lunny added the
kind
bug
label 2020-10-20 02:35:39 +00:00

我也遇到同样的问题了。 只要 group by 出现在查询中,这个count 就取得是 第一行的值,而不是统计返回的行数。

麻烦官方尽快解决下哈。感激不尽!

我也遇到同样的问题了。 只要 group by 出现在查询中,这个count 就取得是 第一行的值,而不是统计返回的行数。 麻烦官方尽快解决下哈。感激不尽!
lunny added this to the 1.1.1 milestone 2021-06-06 07:54:29 +00:00
lunny closed this issue 2021-06-06 12:22:01 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1726
No description provided.