14.12。 group by 子句
返回聚合值的查询
可以按 a 的任何属性进行分组
返回的类或组件:
select cat.color, sum(cat.weight), count(cat)
from Cat cat
group by cat.color
select foo.id, avg(name), max(name)
from Foo foo join foo.names name
group by foo.id
也允许使用having 子句。
select cat.color, sum(cat.weight), count(cat)
from Cat cat
group by cat.color
having cat.color in (eg.Color.TABBY, eg.Color.BLACK)
SQL 函数和聚合函数
允许在拥有和订购
条款,如果它们得到支持
底层数据库(即不在
MySQL)。
select cat
from Cat cat
join cat.kittens kitten
group by cat.id, cat.name, cat.other, cat.properties
having avg(kitten.weight) > 100
order by count(kitten) asc, sum(kitten.weight) desc
group by 子句和
order by 子句可以包含算术
表达式。 Hibernate也没有
目前正在扩展一个分组实体,所以
如果全部都不能写 group by cat
cat 的属性是非聚合的。
您必须列出所有非聚合的
明确的属性。