HQL查询甚至可以返回作用于属性之上的聚集函数的计算结果:
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...)
你可以在选择子句中使用数学操作符、连接以及经过验证的SQL函数:
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