加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle_071_lesson_p6

发布时间:2020-12-12 13:28:15 所属栏目:百科 来源:网络整理
导读:分组函数Group functions avg 求平均 count 求数量 max 求值可针对数字,日期,字符 min 求值可针对数字,日期,字符 sum 求总和 listagg stddev variance select avg(salary),max(salary),min(salary),sum(salary) from employees where job_id like ‘%REP
分组函数Group functions

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

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 子句中

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读