我当前的 Account Balance 对象中有以下属性:
long id; // Database ID
Date date; // date when this balance object was created
boolean currentBalanceFlag; // indicates this is the most recent balance
float amount; // the total sum currently in the account balance
float depositAmount; // amount deposited that resulted in this objects amount
float withdrawalAmount; // amount withdrawn that resulted in this objects amount
Balance lastBalance; // last balance object for traversing
User user; // owner of the balance
String note; // detailed description of transaction that resulted in current blanace
天平上只执行了两个操作。存款和取款。
问题是:
如何创建 HQL 查询:
-sum all depositAmount
for user
-sum all withdrawalAmount
for user
-从第二个求和中减去第一个求和的
结果 -将减法结果与等于的amount
for user
inBalance
对象进行比较currentBalanceFlag
true
在伪代码中:
resultAmount = select ( sum(depositAmount) - sum(withdrawalAmount) ) from Balance where user=user
amount = select amount from Balance where user=user and currentBalanceFlag=true
我想通过 HQL 查询从对数据库的单次调用中获得最终的布尔结果:
resultAmount == amount