2012-01-09 67 views
0

我試圖改變以下HQL中的SQL查詢我的Grails,常規應用問題與轉換SQL到HQL

top10UserActivityQuery = 
"select sum(trans_cnt) as t_cnt, employeeid as username from map2_data "+ 
"where fdate between (:datefrom) and (:dateto) and res_id=:res_id and location =:location "+ 
"group by employeeid order by t_cnt desc limit 10;" 
der rows = myds.rows(top10UserActivityQuery) 

如何使用GORM了個createCriteria爲this..or任何其他方式?

回答

2

標準將類似於以下內容:

def criteria = DomainClass.createCriteria() 
def topTen = criteria.list { 
    and { 
     between("fdate", dateFrom, dateTo) 
     eq("res", resId) 
     eq("location", location) 
    } 
    projections { 
     sum("trans_cnt") 
     groupProperty("employee") 
     property("employee") 
    } 
} 

不過,我會建議使用直接HQL這一標準產生。