Hibernate 中聚合函数的使用

Hibernate 中聚合函数的使用
Criteria接口的Projections类主要用于帮助Criteria接口完成数据的分组查询和统计功能:
List cats = session.createCriteria(Cat. class )
               .setProjection(Projections.projectionList()
               .add(Projections.rowCount())
               .add(Projections.avg(
" weight " ))
               .add(Projections.max(
" weight " ))
               .add(Projections.min(
" weight " ))
               .add(Projections.groupProperty(
" color " ))
           ).addOrder(Order.asc(
" color " )).list();

示例 代码相当于:
select  color, count ( * ), avg (weight), max (weight), min (weight), min (weight)  from  cat  group   by  color  order   by  color  asc ;

你可能感兴趣的:(Hibernate 中聚合函数的使用)