在JPA Criteria API中使用通用表表达式(CTE)

时间:2018-10-25 13:14:26

标签: java sql jpa common-table-expression jpa-criteria

WITH cte AS
(
select
        A.A_ID,
        B.Lib,
        A.Lib,
        C.Lib,
        (SELECT count(*) FROM X WHERE A.A_ID = X.A_ID) AS countX,
        (SELECT count(*) FROM Y WHERE A.A_ID = Y.A_ID) AS countY,
        (SELECT count(*) FROM Z WHERE A.A_ID = Z.A_ID) AS countZ
    from
        A
    left outer join
        C
            on A.C_ID=C.C_ID
    left outer join
        B
            on A.B_ID=B.B_ID
) select * from cte where countX = 2 AND countY = 3
    Order BY 
    countZ DESC;

我知道如何在CTE中创建sql查询,但是我不知道如何在JPA Criteria API(WITH cte AS (...) SELECT * FROM cte)中创建CTE。

0 个答案:

没有答案