泰安市景区建设网站,ps网页入口设计步骤,国际军事新闻联播,excel网站做链接Oracle 分组函数
分组函数作用于一组数据#xff0c;并对一组函数返回一个值。
组函数类型#xff1a; avg#xff0c;count#xff0c;max#xff0c;min#xff0c;sum 可以对数值型数据使用avg和sum函数。
select avg(salary),min(salary),max(salary),sum(salary)…Oracle 分组函数
分组函数作用于一组数据并对一组函数返回一个值。
组函数类型 avgcountmaxminsum 可以对数值型数据使用avg和sum函数。
select avg(salary),min(salary),max(salary),sum(salary) from employees where job_id like %REP%;
avg平均值和sum合计函数 可以对任意数据类型的数据使用 min和 max函数(包括日期)。
select min(hire_date),max(hire_date) from employees
count(*)返回表中记录总数,适用于任意数据类型。
select count(*) from employees where department_id 50;
count (expr) 返回expr不为空的记录总数。
select count (commission_pct) from employees where department_id 50;
组函数忽略空值
select avg(commission_pct) from employees; · NVL函数使分组函数无法忽略空值
select avg(nvl(commission_pct,0)) from employees;
count (distinct expr)返回expr非空且不重复的记录总数
select count(distinct department_id) from employees;
可以使用group by子句将表中的数据分成若干组在select列表中所有未包含在组函数中的列都应该包含在 group by子句中。
select department_id,avg(salary) from employees group by department_id;
包含在 group by 子句中的列不必包含在select列表中
select avg(salary) from employees group by department_id;
在group by 子句中包含多个列
select department_id,job_id,sum(salary) from employees group by department_id,job_id;
非法使用组函数所有包含于select列表中而未包含于组函数中的列都 必须包含于 GROUP BY 子句中。 如下 select department_id,count(last_name) from employees;
非法使用组函数 • 不能在where子句中使用组函数。 • 可以在having子句中使用组函数。
如下 select department_id,avg(saslary) from employees where avg(salary)8000 group by department_id; 过滤分组having 子句
行已经被分组。使用了组函数。满足having子句中条件的分组将被显示。
select department_id,max(salary) from employees group by department_id having max(salary)10000;
嵌套组函数
select max(avg(salary)) from employees group by department_id;