How to group a property in an order item using the Grails criterion

I use Grails Criteria to output results for a specific domain, want to ask if it is possible to have a group property in an order clause or, in other words, how can I write the 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 the grails criteria request looks like

def results =  MyObject.createCriteria().list{

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

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

Thanks in advance Rahman

+1
source share
1 answer

Just ran into this problem. Just to clarify Rehman's answer.

 def results =  MyObject.createCriteria().list {

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

All Articles