HQL聚合函数

count():统计记录条数

 Long count=(Long)this.getCurrentSession().createQuery("select count (e.empNo) from Emp e").uniqueResult();

Hibernate:
select
count(emp0_.empNo) as col_0_0_
from
project.Emp emp0_

sum():求和

 Double sum=(Double)this.getCurrentSession().createQuery("select sum(e.salary) from Emp  e").uniqueResult();

Hibernate:
select
sum(emp0_.salary) as col_0_0_
from
project.Emp emp0_

min():求最小值

 Double min=(Double)this.getCurrentSession().createQuery("select min(e.salary) from Emp e ").uniqueResult();

Hibernate:
select
min(emp0_.salary) as col_0_0_
from
project.Emp emp0_

max():求最大值

 Double max=(Double)this.getCurrentSession().createQuery("select max (e.salary) from Emp e").uniqueResult();

Hibernate:
select
max(emp0_.salary) as col_0_0_
from
project.Emp emp0_

avg():求平均值

Double avg=(Double)this.getCurrentSession().createQuery("select avg (e.salary) from Emp  e").uniqueResult();

Hibernate:
select
avg(emp0_.salary) as col_0_0_
from
project.Emp emp0_

你可能感兴趣的:(HQL聚合函数)