SELECT * FROM EMP E
SELECT * FROM Dept D
SELECT * FROM Salgrade s
--oracle unique function case when
Select
Case 2
When 1 Then ' one '
When 2 Then ' two '
When 3 Then ' three '
Else ' other '
End
from dual;
--oracle Unique function decode
Select Decode (3,1, ' One ', 2, ' two ', 3, ' three ', ' other ') from dual;
--Query Employee leadership Information (inline query)
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-outer join EMP m on E.mgr=m.empno;
--Query Employee's leadership information (inline query) and employee department name
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
--Query Employee leadership Information (inline query) employee Department name, leading department name
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
--Query Employee leadership Information (inline query) employee Department name, lead department name, employee salary level, lead salary grade
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
--levels are not represented by numbers and are expressed in words
Select E.empno,e.ename,e.job,e.mgr,e.deptno,d.dname,
Decode (s.grade,1, ' level ', 2, ' two ', 3, ' Three ', 4, ' Four ', 5, ' Five ', ' no Grade '),
' | | ', M.EMPNO,M.ENAME,M.JOB,P.DNAME,
Decode (s1.grade,1, ' level ', 2, ' two ', 3, ' Three ', 4, ' Four ', 5, ' Five ', ' no level ')
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
--inquire about employee's salary above No. 7369
Select Sal from EMP where empno=7369
SELECT * from emp where sal> (select Sal from emp where empno=7369)
--Query The department information that exists for the employee
SELECT DISTINCT Deptno from emp
SELECT * FROM dept where deptno on (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)
--Using Exists
SELECT * FROM Dept D where exists (SELECT * from emp e where E.deptno=d.deptno)
--Query the minimum wage employee information for each department
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
--Query the top three of the highest salary (the feeling of paging)
SELECT * FROM
(SELECT * from emp ORDER BY sal Desc) t
where RowNum <=3
Oracle-specific function case when decode exists paging rownum