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;
Я знаю, как создать SQL-запрос внутри CTE, но я не знаю, как создать CTE в JPA Criteria API (WITH cte AS (...) SELECT * FROM cte
).