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

请问使用 GROUP BY HAVING 时,如何设置 SUM 内部表达式? #1172

Open
shuqingzai opened this issue Jul 8, 2024 · 1 comment
Open

Comments

@shuqingzai
Copy link

Your Question

参考: Group By & Having

使用 group by Having Sum 表达时,怎么设置 sum 的条件

o.WithContext(ctx).Select(o.CreateAt.Date().As("date"), o.WithContext(ctx).Amount.Sum().As("total")).Group(o.CreateAt.Date()).Having(u.Amount.Sum().Gt(100)).Scan(&results)

上述语句提取 GroupBY HAVING 部分类似

... GROUP BY `order`.`create_at` HAVING SUM(`user`.`amount`) > 100

The document you expected this should be explained

Expected answer

我期望可以实现在 SUM 计算字段匹配值

... GROUP BY `order`.`create_at` HAVING SUM(`user`.`amount` > 10) > 100

根据

func (field Int) Sum() Int {

我似乎没法传递表达式修改 SUM 的条件

@mimicode
Copy link

#1213

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