这是我的代码:
final JPAQuery query = new JPAQuery(entityManager);
final List<Tuple> myList = query
.from(QPerson.person)
.groupBy(QPerson.person.name)
.where(myBooleanExpression) //myBooleanExpression declared at the top of code
.list(QPerson.person.name,
QPerson.person.cash.sum());
我想要做的是列出:
有关如何操作的任何建议吗?
答案 0 :(得分:1)
您可以在案例中使用SQL CASE
,例如:
final JPAQuery query = new JPAQuery(entityManager);
final List<Tuple> myList = query
.from(QPerson.person)
.groupBy(QPerson.person.name)
.where(myBooleanExpression)
.list(QPerson.person.name,
new CaseBuilder()
.when(yourOtherBooleanExpression).then(QPerson.person.cash.sum())
.otherwise(yourOtherNumericExpressionOrLiteral));
yourOtherBooleanExpression
应该是Predicate
(例如BooleanExpression
)yourOtherNumericExpressionOrLiteral
应该是NumberExpression<T>
或T
本身,其中T
是QPerson.person.cash
的基本类型。