gpt4 book ai didi

java - 此 HQL 查询是否有糖语法

转载 作者:行者123 更新时间:2023-12-01 12:04:11 25 4
gpt4 key购买 nike

我有一对多映射,学校有一组学生,我只想获取所有学生得分都大于 3 的学校。
以下查询完成了这项工作:

List list = session.createQuery("select school from School school join school.students st group by school.id having min(st.score) > 3").list(); 

但我想知道是否有更短的方法,例如 HQL 内置函数来获得相同的结果。

最佳答案

您需要一个子查询:

select school from School school where not exists(
select student.id from School school2
join school2.students student
where student.score <= 3
and school2.id = school.id)

关于java - 此 HQL 查询是否有糖语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27764490/

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