Something I had to dig around for today was how to perform a sum on a table using Criteria Builder. It seems that it is treated a bit different than a normal query would be. Here is an example of what I tried and failed at:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def c = Transaction.createCriteria() | |
def cnt = c.get { | |
projections { | |
sum("amount") | |
} | |
and { | |
eq("status", k) | |
eq("transactionType", transactionType) | |
ge("dateTimeProcessed", cal1.getTime()) | |
le("dateTimeProcessed", cal2.getTime()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def c = Transaction.createCriteria() | |
def cnt = c.get { | |
projections { | |
sum("amount") | |
} | |
eq("status", k) | |
eq("transactionType", transactionType) | |
ge("dateTimeProcessed", cal1.getTime()) | |
le("dateTimeProcessed", cal2.getTime()) | |
} |
No comments:
Post a Comment