Red Hat Training

A Red Hat training course is available for Red Hat JBoss Web Server

8.5. 集約関数

HQL クエリはプロパティで集約関数の結果を返すこともできます。
select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat)
from Cat cat
サポート対象の集約関数は以下のとおりです。
  • avg(...), avg(distinct ...), sum(...), sum(distinct ...), min(...), max(...)
  • count(*)
  • count(...), count(distinct ...), count(all...)
select 句で、算術演算子、連結、および認識された SQL 関数を使用できます (設定されたダイレクト、HQL 固有機能に依存します)。
select cat.weight + sum(kitten.weight) 
from Cat cat 
    join cat.kittens kitten
group by cat.id, cat.weight
select firstName||' '||initial||' '||upper(lastName) from Person
distinct キーワードと all キーワードを使用できます。これらのキーワードは SQL と同じセマンティクスを持ちます。
select distinct cat.name from Cat cat

select count(distinct cat.name), count(cat) from Cat cat