13.4.14. 関連比較について
比較には、等号の =、>、>=、<、<=、<> のいずれかが関係します。HQL は、<> と比べる比較演算子として != も定義します。オペランドは同じタイプである必要があります。
例13.17 関係比較の例
// 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、SOME などの修飾子を含めることもできます。some および ANY は同義語です。
ALL 修飾子は、サブくエリーの結果のすべての値に対して比較が true の場合に true に解決します。これは、値が空の場合は false に解決します。
例13.18 ALL サブクエリー比較修飾子の例
// 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
)
ANY/SOME 修飾子は、サブクエリーの結果の値のいずれかの比較が true の場合に true に解決します。これは、値が空の場合は false に解決します。