Oralce training notes-table structure used in class

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.