15.7. 聚集函数
优质
小牛编辑
132浏览
2023-12-01
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