gpt4 book ai didi

java - Spring 数据 : is it possible to have subqueries in the Query annotation?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:12:22 26 4
gpt4 key购买 nike

我想知道是否可以在 @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")

谢谢!

最佳答案

不可以,在 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)

关于java - Spring 数据 : is it possible to have subqueries in the Query annotation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9743011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com