gpt4 book ai didi

hibernate - 如何使用 Grails Criteria 对 Order 子句中的属性进行分组

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

我正在使用 Grails Criteria 提取特定域的结果我想问是否可以在 order 子句中使用 group 属性,或者换句话说,我如何使用 Grails 标准编写以下 mysql 查询?

select 
h.name,
count(h.id)
from my_table as h
group by h.name
order by count(h.id) desc;

到目前为止 grails 标准查询看起来像
def results =  MyObject.createCriteria().list{

projections{
groupProperty('name')
countDistinct('id')

}
order(???,'desc')
}

提前致谢
雷曼

最佳答案

刚遇到这个问题。只是为了澄清雷曼的回答。

 def results =  MyObject.createCriteria().list {

projections {
groupProperty('name')
countDistinct('id', 'idDistinct')
}
order('idDisctinct','desc')
}

关于hibernate - 如何使用 Grails Criteria 对 Order 子句中的属性进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5977076/

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