ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 14.6\. 聚集函数 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 ```