简体   繁体   中英

row multiplication in Hibernate Criteria

How to implement the following SQL query using Hibernate Criteria API:

SELECT
    SUM(field1) as s,
    SUM(field1 * field2) as m
FROM 
    table

Try

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 }))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM