将SQL请求转换为JPQL请求

时间:2012-12-19 18:23:20

标签: java jpql

我正在学习JPQL,我想知道如何将此查询转换为JPQL?

我有用于astres表的实体Astre和用于planetes表的Planetegenerate_series()是PostgreSQL函数。

SELECT t1.galaxie, t1.ss, t1.position FROM 
(
   SELECT galaxie, ss, position FROM 
   generate_series(1, 9) galaxie 
   CROSS JOIN generate_series(1, 500) ss 
   CROSS JOIN generate_series(1, 15) position 
) t1
 LEFT JOIN 
(
   SELECT a.galaxie, a.ss FROM astres a 
   INNER JOIN planetes p 
   ON a.id=p.astre_id 
   WHERE p.planete_mere=TRUE 
   GROUP BY a.galaxie, a.ss 
   HAVING COUNT(*)=3 
) t2 
ON t1.galaxie = t2.galaxie 
AND t1.ss = t2.ss 
LEFT JOIN 
( 
   SELECT a.galaxie, a.ss, a.position FROM astres a 
   INNER JOIN planetes p 
   ON a.id=p.astre_id 
) t3 
ON t1.galaxie=t3.galaxie 
AND t1.ss=t3.ss 
AND t1.position=t3.position 
WHERE t2.galaxie IS NULL 
AND t3.galaxie IS NULL 
ORDER BY t1.galaxie, t1.ss, t1.position

如果需要,我可以提供实体代码。

感谢您的帮助。

0 个答案:

没有答案