oracle数据库之组函数

组函数也叫聚合函数,用来对一组值进行运算,而且能够返回单个值数据库

常见的组函数:oracle

(1)count(*),count(列名)  统计行数找到全部不为 null 的数据来统计行数函数

(2)avg(列名)  平均数测试

(3)sum(列名)  求和spa

(4)max(列名)  求最大值对象

(5)min(列名)  求最小值blog

scottoracle中的一个示范用户,主要用于测试。它自带一些测试用的数据方便咱们测试,因为是oracle中的一个对象,所以scott.emp表示数据库中的员工表。class

-- 首先,查看emp 中的全部数据。select

select * from scott.emp;im

 

--1统计 emp 表中的总行数

select count(*) from scott.emp;

 

 

--统计 emp 表中属性列为ename的总行数

select count(ename) from scott.emp;

 

 

--统计 emp 表中属性列为comm的总行数,因为有10项为空,因此行数为4

select count(comm) from scott.emp;

 

 

--2平均值

-- 统计 emp 表中属性列为comm平均奖金。

-- 通常作法,平均奖金 = 总奖金/总员工数。

select sum(comm) / count(comm) from scott.emp;

-- 使用 avg() 求均值

select avg(sal) from scott.emp;

 

 

--3)使用sum() 求和

select sum(sal) from scott.emp;

 

 

--4最大

select max(sal) from scott.emp;

 

 

--5最小值

select min(sal) from scott.emp;

 

相关文章
相关标签/搜索