Ich versuche für mehrere Tage eine Liste von meinen Daten zu erhalten. Die Domain sieht wie folgt aus:Grails zusätzliche Spalten in Tabelle oder Liste
class Alpha {
String a
String b
etc.
static hasMany = [beta:Beta]
}
class Beta {
String a
Integer foo
String status
static belongsTo = [alpha:Alpha]
static constraints = {
status(nullable:false, inList:["val1","val2","val3", "val4"])
}
}
ich in Alpha die Summe aller Beta.foo und aller Beta.foo in einem bestimmten Status haben möchten. Am besten wäre so etwas wie eine zusätzliche Zeile (Integer sumVal1 ...
).
Ich habe versucht, benannte Abfragen:
static namedQueries = {
erledigterProbeAufwend {
createAlias ('Beta', 'b')
eq ('b.status', 'val1')
projections {
groupProperty('b.alpha')
sum('b.foo', 'sumFooVal1')
}
}
}
Aber gib mir nur eine Summe auf einmal.
Ich freue mich darauf, Hilfe zu bekommen.
Grüße Bas
Vielen Dank für Ihre schnelle Antwort. Es funktioniert gut :) – Bas
Es funktioniert perfekt !! Ich möchte meinen Fall als ein weiteres Beispiel veröffentlichen: 'totalFilhos formula: '(SELECT count (*) FROM aendimento a WHERE a.atendimento_pai = cod_atendimento)' ' –
und was ist, wenn du kein' count (*) willst ', aber alle Zeilen, mit dem gleichen Trick? –