oracle数据库之组函数

组函数也叫聚合函数,用来对一组值进行运算,并且可以返回单个值

常见的组函数:

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

(2)avg(列名)  平均数

(3)sum(列名)  求和

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

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

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

-- 首先,查看emp 中的所有数据。

select * from scott.emp;

 

--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;

 

 

 

 

posted @ 2018-08-08 08:37  一飞要上天  阅读(1925)  评论(0编辑  收藏  举报