7.5. Aggregate functions

download PDF
HQL queries may even return the results of aggregate functions on properties:
select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat)
from Cat cat
The supported aggregate functions are
  • avg(...), avg(distinct ...), sum(...), sum(distinct ...), min(...), max(...)
  • count(*)
  • count(...), count(distinct ...), count(all...)
You may use arithmetic operators, concatenation, and recognized SQL functions in the select clause (depending on configured dialect, HQL specific feature):
select cat.weight + sum(kitten.weight) 
from Cat cat 
    join cat.kittens kitten
group by, cat.weight
select firstName||' '||initial||' '||upper(lastName) from Person
The distinct and all keywords may be used and have the same semantics as in SQL.
select distinct from Cat cat

select count(distinct, count(cat) from Cat cat
Red Hat logoGithubRedditYoutubeTwitter


Try, buy, & sell


About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.