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 E。SOME 和 ANY 是同义词。
如果对子队列结果中的所有值进行比较都为 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。