Oracle特有函数 case when decode exists 分页rownum

Posted Advancing Swift

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle特有函数 case when decode exists 分页rownum相关的知识,希望对你有一定的参考价值。

select * from EMP e
select * from dept d
select * from salgrade s
--Oracle特有函数 case when
select
case 2
when 1 then ‘一‘
when 2 then ‘二‘
when 3 then ‘三‘
else ‘其他‘
end
from dual;
--Oracle特有函数 decode
select decode(3,1,‘一‘,2,‘二‘,3,‘三‘,‘其他‘)from dual;
--查询员工的领导信息(内联查询)
select e.empno,e.ename,e.job,e.mgr,‘||‘,m.empno,m.ename,m.job
from emp e,emp m
where e.mgr=m.empno(+)

select *
from emp e right outer join emp m on e.mgr=m.empno;

select *
from emp e full outer join emp m on e.mgr=m.empno;
--查询员工的领导信息(内联查询)及员工部门名称
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,‘||‘,m.empno,m.ename,m.job
from emp e,emp m,dept d
where e.mgr=m.empno and e.deptno=d.deptno
--查询员工的领导信息(内联查询)员工部门名称,领导部门名称
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,‘||‘,m.empno,m.ename,m.job,p.dname
from emp e,emp m,dept d,dept p
where e.mgr=m.empno and e.deptno=d.deptno and m.deptno=p.deptno
--查询员工的领导信息(内联查询)员工部门名称,领导部门名称,员工工资等级,领导工资等级
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,s.grade,
‘||‘,m.empno,m.ename,m.job,p.dname,s1.grade
from emp e,emp m,dept d,dept p,salgrade s,salgrade s1
where e.mgr=m.empno
and e.deptno=d.deptno
and m.deptno=p.deptno
and e.sal between s.losal and s.hisal
and m.sal between s1.losal and s1.hisal
--级别不用数字表示,用文字表示
select e.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,
decode(s.grade,1,‘一级‘,2,‘二级‘,3,‘三级‘,4,‘四级‘,5,‘五级‘,‘没级‘),
‘||‘,m.empno,m.ename,m.job,p.dname,
decode(s1.grade,1,‘一级‘,2,‘二级‘,3,‘三级‘,4,‘四级‘,5,‘五级‘,‘没级‘)
from emp e,emp m,dept d,dept p,salgrade s,salgrade s1
where e.mgr=m.empno
and e.deptno=d.deptno
and m.deptno=p.deptno
and e.sal between s.losal and s.hisal
and m.sal between s1.losal and s1.hisal
--查询工资高于7369号员工工资的员工信息
select sal from emp where empno=7369
select * from emp where sal>(select sal from emp where empno=7369)
--查询存在员工的部门信息
select distinct deptno from emp
select * from dept where deptno in(select distinct deptno from emp )
select * from dept where deptno =any(select distinct deptno from emp )
select * from dept where deptno =some(select distinct deptno from emp )
--使用exists
select * from dept d where exists (select * from emp e where e.deptno=d.deptno)
--查询每个部门最低工资员工信息
select *
from emp e,(select min(sal) msal,deptno from emp group by deptno) t
where e.sal=t.msal
and e.deptno=t.deptno
--查询工资最高的前三名 (分页的感觉)
select * from
(select * from emp order by sal desc) t
where rownum <=3




































































以上是关于Oracle特有函数 case when decode exists 分页rownum的主要内容,如果未能解决你的问题,请参考以下文章

ORACLE CASE WHEN 及 SELECT CASE WHEN的用法

Oracle CASE WHEN函数用法

Oracle CASE WHEN函数用法

oracle case when

Oracle select case when

oracle中case when的用法