Inner join with select on HQL

前端 未结 3 596
野的像风
野的像风 2021-01-03 10:16

I want to do something like that with HQL:

SELECT *
FROM tableA a
INNER JOIN (select fieldA, sum(fieldB) as sum from tableB) b
ON a.fieldA = b.fieldA and a.f         


        
3条回答
  •  青春惊慌失措
    2021-01-03 10:42

    try the native SQL solution approach:

    need toimport this first:

    import org.hibernate.SQLQuery;
    

    then somewhere in your code:

    SQLQuery query = session.createSQLQuery(
        "SELECT * FROM tableA a
        INNER JOIN 
        (SELECT fieldA, sum(fieldB) as sum from tableB) b
        ON a.fieldA = b.fieldA and a.fieldC = b.sum"
    );
    

    more on this link
    and HERE ( Joins in Hibernate Query Language)

提交回复
热议问题