gpt4 book ai didi

grails - 如何在 Grails 中实现 "select sum()"

转载 作者:行者123 更新时间:2023-12-02 09:18:02 24 4
gpt4 key购买 nike

我有这样的关系:

class E {
string name
hasMany = [me:ME]
}

class M {
float price
}

class ME {
E e
M m
int quantity
}

我不想迭代来实现这一点:“获得 ME 中的数量乘以给定 E 的相应 M 的价格之和”。

有关如何使用 GORM/HQL 实现它的任何提示吗?

提前致谢

最佳答案

还没有测试过这个,但如果它不能开箱即用,它应该很接近:

def givenE = // the E we're looking for
def sum = ME.executeQuery("select sum(m.price) from ME as me join me.m as m where me.e = :e", [e: givenE])
println sum

关于grails - 如何在 Grails 中实现 "select sum()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2710882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com