此内容没有您所选择的语言版本。

14.13. Subqueries


For databases that support subselects, Hibernate supports subqueries within queries. A subquery must be surrounded by parentheses (often by an SQL aggregate function call). Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed.
from Cat as fatcat
where fatcat.weight > (
    select avg(cat.weight) from DomesticCat cat
)
Copy to Clipboard Toggle word wrap
from DomesticCat as cat
where cat.name = some (
    select name.nickName from Name as name
)
Copy to Clipboard Toggle word wrap
from Cat as cat
where not exists (
    from Cat as mate where mate.mate = cat
)
Copy to Clipboard Toggle word wrap
from DomesticCat as cat
where cat.name not in (
    select name.nickName from Name as name
)
Copy to Clipboard Toggle word wrap
select cat.id, (select max(kit.weight) from cat.kitten kit)
from Cat as cat
Copy to Clipboard Toggle word wrap
Note that HQL subqueries can occur only in the select or where clauses.
Note that subqueries can also utilize row value constructor syntax. See Section 14.18, “Row value constructor syntax” for more information.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat