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_

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 引出 •请思考如下问题? –查询所有员工的每个月工资总和,平均工资? –查询工资最高和最低的工资是多少? –查询公...
    C_cole阅读 7,318评论 0 3
  • mysql数据库中 :database : 文件夹table : 数据表(数据文件) 进入mysqlmysql -...
    赋闲阅读 582评论 0 0
  • 1.简介 数据存储有哪些方式?电子表格,纸质文件,数据库。 那么究竟什么是关系型数据库? 目前对数据库的分类主要是...
    乔震阅读 1,787评论 0 2
  • 1.INSERT 官网说明:INSERT OVERWRITE TABLE tablename1 [PARTITIO...
    白面葫芦娃92阅读 650评论 0 0
  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,138评论 0 0