4.9. 关于关系比较


比较涉及比较运算符之一 - =, >, >=, <, ›, <>。HQL 还定义了 != 作为与 <> 的比较运算符。操作对象应该是相同的类型。

示例:关系比较示例

// numeric comparison
select c
from Customer c
where c.chiefExecutive.age < 30

// string comparison
select c
from Customer c
where c.name = 'Acme'

// datetime comparison
select c
from Customer c
where c.inceptionDate < {d '2000-01-01'}

// enum comparison
select c
from Customer c
where c.chiefExecutive.gender = com.acme.Gender.MALE

// boolean comparison
select c
from Customer c
where c.sendEmail = true

// entity type comparison
select p
from Payment p
where type(p) = WireTransferPayment

// entity value comparison
select c
from Customer c
where c.chiefExecutive = c.chiefTechnologist

比较还可能涉及子队列限定符 - ALL、ANY、SOM ESOMEANY 是同义词。

如果对子队列结果中的所有值进行比较都为 true,则 ALL 限定符会解析为 true。如果子队列结果为空,它将解析为 false。

示例:所有 Subquery Comparison Qualifier 示例

// select all players that scored at least 3 points
// in every game.
select p
from Player p
where 3 > all (
   select spg.points
   from StatsPerGame spg
   where spg.player = p
)

如果对 队列结果中至少一个值进行比较为 true,ANY /SOME 限定符会解析为 true。如果子队列结果为空,它将解析为 false。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部