网站建设资讯

NEWS

网站建设资讯

Oracle_071_lesson_p6

分组函数Group functions

avg 求平均
count 求数量
max 求值可针对数字,日期,字符
min 求值可针对数字,日期,字符
sum 求总和
listagg
stddev
variance

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了深圳免费建站欢迎大家使用!

count详解:

count(*)将返回表格中所有存在的行的总数包括值为null的行,然而count(列名)将返回表格中除去null以外的所有行的总数(有默认值的列也会被计入).

distinct 列名,得到的结果将是除去值为null和重复数据后的结果

select avg(salary),max(salary),min(salary),sum(salary)
from employees
where job_id like '%REP%';

select count(*)
from employees
where department_id=50;

select count(commission_pct)
from employees
where department_id=50;
空值行不参与计算

GROUP BY分组
select department_id,avg(salary)
from employees
group by department_id;

select department_id,avg(salary)
from employees
group by department_id;
order by avg(salary);
此group by 后可跟order by ,但order by子句只能出现在最后。

select avg(salary)
from employees
group by department_id;
但group by 的列名不必一定在select 子句中

SELECT department_id, AVG(salary)
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 8000;

where 子句不能加分组函数,要用having子句才能加分组函数
alias 别名不能放在group by 子句中


网页标题:Oracle_071_lesson_p6
转载来于:http://cdweb.net/article/jscjec.html