Gorm - Contagem de Registros (Group By)
11/12/2012 04:01
def tarefas() {
def query = "select c.categoria, count(r) from Categoria c group by c.categoria"
def result = Categoria.executeQuery(query)
[retorno:result]
}
def tarefas() {
def referenica = Referencia.get(1)
def retorno =[:]
def categorias = Categoria.findAllByReferencia(referencia)
categorias.each {categoria ->
if(retorno[categoria.descricao]){
retorno[categoria.descricao]++
} else {
retorno[categoria.descricao] = 1
}
}
[dados:retorno]
def c = Account.createCriteria()
def branchCount = c.get {
projections {
countDistinct "branch"
}
}
Para se registrar, clique aqui.