How to use CriteriaQuery SUM of custom operation on some cells?
问题 Consider you have table T, with fields A and B. With regular SQL, I could do this: SELECT SUM(A * (100.0 - B) / 100.0) AS D FROM T; And I would get exactly what I expect. However, I'm not sure how to do it with CriteriaQuery. I know how to do sum over 1 field, but not how to do sum over some math expression over multiple fields in a row. 回答1: The CriteriaBuilder interface provides the following arithmetic functions: addition: sum(a, b) substraction: diff(a, b) multiplication: prod(a, b)