如何将此SQL查询转换为Grails或Gorm查询



如何在Grails或Gorm中编写下面的SQL查询?

select email, count(*) as c FROM orders GROUP BY email

使用投影!

def result = Orders.createCriteria().list() {
  projections {
    groupProperty("email")
    count()
  }
  order("email", "asc")
}

编辑:或HQL,我猜...

def list = Orders.executeQuery("select email, count(*) from Orders group by email")
list.each { item ->
    def email = item[0]
    def count = item[1]
    println "There are ${count} people with the e-mail address of ${email}"
}

(我只是看着那个,但我认为这是正确的,可能会进行一些调整)

相关内容

  • 没有找到相关文章

最新更新