Multi-table join:
Equijoin
Select EMP. empno, EMP. ename, EMP. deptno, Dept. deptno, Dept. LOC from EMP, DEPT where EMP. deptno = Dept. deptno
Decathlon connection:
Select * from EMP, DEPT;
Retrieve the records in which the salary in the EMP table is between the lowest and highest in the salgrade table.
Select E. ename, E. Sal, S. grade from emp e, salgrade s where E. Sal between S. losal and S. hisal;
External Connection:
Retrieve the Department name of all employees. If the Department has no employees, the name is blank.
Select E. ename, D. deptno, D. dname from emp e, DEPT d Where E. deptno (+) = D. deptno order by E. deptno;
Self-connection:
Identify superior relationships of employees
Select worker. ename | 'word for '| manager. ename from EMP worker, EMP manager where worker. Mgr = manager. empno;
Aggregate functions:
Select AVG (SAL), max (SAL), min (SAL), sum (SAL) from EMP where job like 'sales % ';
Select min (hiredate), max (hiredate) from EMP;
Select count (*) from EMP where deptno = 30;
Select count (Comm) from EMP where deptno = 30;
Average rewards for persons with bonuses
Select AVG (Comm) from EMP;
Average bonus for all
Select AVG (nvl (Comm, 0) from EMP;
Calculate the average salary of each department:
Select EMP. deptno, Dept. dname, AVG (SAL) from EMP, DEPT where EMP. deptno = Dept. deptno group by EMP. deptno, Dept. dname;
Group by usage:
Group by Department: Average monthly salary, total salary, highest salary, minimum wage
Select deptno, AVG (SAL), sum (SAL), max (SAL), min (SAL) from EMP group by deptno;
Group by Department: salaries and (based on the same number of employees) for each job)
Select deptno, job, sum (SAL) from EMP group by deptno, job;
Find out the sum of the salary of the job and the salary of the job that is not started with sales and is greater than 5000.
Select job, sum (SAL) payroll from EMP where job not like 'sales % 'group by job having sum (SAL)> 5000 order by sum (SAL );
subquery:
Single Row subquery
select ename from EMP where SAL> (select Sal from EMP where empno = 7566);
select ename, job from EMP where job = (select job from EMP where empno = 7369) and Sal> (select Sal from EMP where empno = 7876 );
multi-row subquery
select empno, ename, job from EMP where Sal 'cler';
select empno, ename, job from EMP where SAL> All (select AVG (SAL) from EMP group by deptno);