14.7. 集約関数
HQL のクエリはプロパティの集約関数の結果も返せます:
select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat) from Cat cat
select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat)
from Cat cat
サポートしている集約関数は以下のものです:
avg(...), sum(...), min(...), max(...)count(*)count(...), count(distinct ...), count(all...)
select 節において演算操作、連結と承認された SQL 関数を使うことができます:
select cat.weight + sum(kitten.weight)
from Cat cat
join cat.kittens kitten
group by cat.id, cat.weight
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
select firstName||' '||initial||' '||upper(lastName) from Person
SQL と同じ意味を持つ
distinct と all キーワードを使うことができます。
select distinct cat.name from Cat cat select count(distinct cat.name), count(cat) from Cat cat
select distinct cat.name from Cat cat
select count(distinct cat.name), count(cat) from Cat cat