oracle 函数


-- distinct:去重
-- 查询emp表中岗位有哪些
select distinct job from scott.emp;

--计数
--查询员工多少个人
select count(empno) from scott.emp;

-- 查询部门编号是10或20一共有多少人
select count(1) from scott.emp where deptno  = 10 or deptno =20 ;

--SUM():求和
--查询部门编号10的员工薪资一共多少
select sum(sal) from scott.emp where deptno =10;
--查询部门编号20的员工薪资一共多少
select sum(sal) from scott.emp where deptno =20;

--avg 平均值
--查询所有员工的薪资平均值
select avg(sal) from scott.emp;
select sum(sal)/count(empno) from scott.emp;
--查询出 20部门的平均工资
select avg(sal) from scott.emp where deptno = 20;
-- 请查询出 20部门的平均工资,部门编号
select avg(sal),deptno from scott.emp where deptno = 20 group by deptno;

-- 查询本公司的最高工资
select max(sal) from SCOTT.emp;
-- 查询本公司的最低工资
select min(sal) from SCOTT.emp;
-- 查询本公司的最高工资和最低工资
select max(sal),min(sal) from SCOTT.emp;
--查看30部门的最高工资
select max(sal) from scott.emp where deptno = 30;
--查看30部门的最低工资
select min(sal) from scott.emp where deptno = 30;
--查看30部门的最高工资和最低工资
select max(sal),min(sal) from scott.emp where deptno = 30;




-- 排序   order by 字段
-- 默认从小到大 (升序) asc
select * from scott.emp order by sal asc;
--从大到小 desc 降序
select * from scott.emp order by sal desc;

-- 薪资最多的员工姓名
-- 显示行数
-- rownum
-- 子查询
-- select 列 from 表(查询出来的表)where 条件;
select * from (select * from scott.emp order by sal desc) where rownum <= 1;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值