HQL聚合函数

来源:互联网 发布:淘宝店铺商品搜不到 编辑:程序博客网 时间:2024/06/07 05:49

HQL聚合函数

函数名
说明count()统计记录条数sum()求和
max()求最大值min()求最小值avg()求平均值
列:

 select  count(*)  from  Emp            

            //统计Emp类中所对应的表中中条数;

 select  sum(salary)  from  Emp      

            //统计Emp类中所对应的表中salary总和;

 select  max(salary)   from  Emp   

            //统计Emp类中所对应的表中salary中最大值;

select min(salary)   from  Emp   //统计Emp类中所对应的表中salary中最小值;

selectavg(salary)   from  Emp   //统计Emp类中所对应的表中salary的平均值;


聚合函数不能直接和表中列一起查询
    可以这样:select job,avg(salary),max(salary),min(salary) from Emp group by job  //以job的不同来分组;



1 0
原创粉丝点击