对于支持子查询的数据库,Hibernate支持在查询中使用子查询。一个子查询必须被圆括号包围起来(经常是SQL聚集函数的圆括号)。 甚至相互关联的子查询(引用到外部查询中的别名的子查询)也是允许的。
from Cat as fatcat
where fatcat.weight > (
select avg(cat.weight) from DomesticCat cat
)
from DomesticCat as cat
where cat.name = some (
select name.nickName from Name as name
)
from Cat as cat
where not exists (
from Cat as mate where mate.mate = cat
)
from DomesticCat as cat
where cat.name not in (
select name.nickName from Name as name
)
select cat.id, (select max(kit.weight) from cat.kitten kit) from Cat as cat
注意,HQL自查询只可以在select或者where子句中出现。
本文介绍了Hibernate支持的子查询特性,包括在HQL中如何使用子查询进行复杂查询操作。示例展示了子查询在select和where子句的应用,如平均值比较、是否存在、名称是否包含等。
6987

被折叠的 条评论
为什么被折叠?



