如何使用Grails标准对Order Clause中的属性进行分组 [英] How to Group property in Order Clause using Grails Criteria

查看:59
本文介绍了如何使用Grails标准对Order Clause中的属性进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  select 
h.name,
count(h.id)
from my_table as h
按h.name
按数量排序(h.id)desc;

到目前为止,grails标准查询看起来像



<$ ($ name)
countDistinct('id')$ {


$ {code> def results = MyObject.createCriteria )


order(???,'desc')
}

预先感谢
Rehman

解决方案刚刚遇到这个问题。只是为了澄清雷曼的答案。

  def results = MyObject.createCriteria()。list {

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


i am using Grails Criteria to pull results for a specific domaini want to ask whether is it possible to have group property in order clause or in other words, how can i write following mysql query using Grails criteria ?

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

so far grails criteria query looks like

def results =  MyObject.createCriteria().list{

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

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

Thanks in advance Rehman

解决方案

Just encountered this problem. Just to clarify Rehman's answer.

 def results =  MyObject.createCriteria().list {

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

这篇关于如何使用Grails标准对Order Clause中的属性进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆