我想知道是否可以在 @Query 注释中包含子查询(org.springframework.data.jpa.repository.Query;)
我在第一个子查询括号中收到 QuerySyntaxException 。
这是我的查询
@Query(value="select c1 from ComplaintModel c1, "
+ "(select c2.id, min(cb.termDate) minDate from ComplaintModel c2 "
+ "join c2.complaintBullets cb join cb.status s where s.code = ?1 "
+ "group by c2.id) tmp where c1.id = tmp.id order by tmp.minDate")
Thanks!
不可以,JPQL 查询中的 select 子句中不可能有子查询。
JPQL 支持 WHERE 和 HAVING 子句中的子查询。它可以(至少)是 ANY、SOME、ALL、IN、EXIST 表达式的一部分,当然也可以使用普通的条件表达式:
SELECT a
FROM A a
WHERE a.val = (SELECT b.someval
FROM B b
WHERE b.someotherval=3)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)