如何使用Hibernate Criteria API实现以下SQL查询:
SELECT
SUM(field1) as s,
SUM(field1 * field2) as m
FROM
table
答案 0 :(得分:1)
尝试
add(Projections.sqlProjection("sum(field1)) AS s", new String[] { "s" }, new Type[] {Hibernate.DOUBLE }))
add(Projections.sqlProjection("sum(field1*field2) AS m", new String[] { "m" }, new Type[] {Hibernate.DOUBLE }))