开发者

How to Group property in Order Clause using Grails Criteria

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,
    开发者_StackOverflow中文版   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')
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜