这个 HQL 查询是否有糖语法
Is there a sugar syntax for this HQL query
我有一对多的映射,学校有一组学生,我只想得到所有学生的分数都大于 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)
我有一对多的映射,学校有一组学生,我只想得到所有学生的分数都大于 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)