gpt4 book ai didi

grails - 在grails中使用HibernateCriteriaBuilder从createCriteria中提取所有字段

转载 作者:行者123 更新时间:2023-12-02 15:36:04 26 4
gpt4 key购买 nike

我在休眠创建条件查询中的group by子句中对数字字段的总和进行了查询。我需要另一列-输出结果列表中域类中的seriesType,但是现在,如果我在投影中添加术语property('seriesType')和grouProperty()行,则会出现一个异常,说not a group by clause could not execute query
不确定如何在结果中与其他两个字段一起使用
这是我的标准

dataMap = BehaviorProfile.createCriteria().list {
globalUser{
eq('id',empid2)
}

projections{
sum('frequency', 'tfreq')
groupProperty('dayofweek')
// if I add property('seriesType') here the criteria throws an exception
}

}

最佳答案

您需要添加groupProperty('seriesType')而不是property('seriesType')。当您对某个属性A进行分组并使用聚合函数(以您的情况为总和)时,您将不能仅在侧面输出其他一些属性B,因为B的前置操作中也可能有很多值。

例如,在您的dayofweek = 2聚合组中,总和为150,并且存在三种可能的seriesTypes-siereA,serieB和serieC。因此,您需要执行以下操作:仅按dayofweek进行分组,或将按系列类型分组的组添加到查询中。

关于grails - 在grails中使用HibernateCriteriaBuilder从createCriteria中提取所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10239022/

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