Oracle Learning Article Six: Sub-query

Source: Internet
Author: User

--1. Query for employees with a higher than 7654 salary

SELECT * from emp where sal> (select Sal from EMP where empno=7654);

---2. Find employee information for minimum wage
SELECT * from emp where sal= (select min (sal) from EMP);

------------The name of the department, the number of department employees, the average salary of the department, the name of the person with the lowest income, and the person with the highest income
Select D.dname,t1.c,t1.avgsal,t1.maxsal,t1.minsal from Dept D, (select Deptno,count (empno) c,avg (SAL) Avgsal,max (SAL) Maxsal,min (SAL) minsal from EMP Group by DEPTNO) T1
where D.deptno=t1.deptno


----Any function, =any is the same as in
SELECT * from emp where Sal in (select min (sal) from EMP Group by DEPTNO);

--> any is larger than the smallest value
SELECT * from emp where Sal>any (select min (sal) from EMP Group by DEPTNO);

--< Any is smaller than the maximum value.
SELECT * from emp where Sal < any (select min (sal) from EMP Group by DEPTNO);

SELECT * from emp where Sal < any (select min (sal) from EMP Group by DEPTNO);

---< All is smaller than the smallest
SELECT * from emp where sal > All (select Max (SAL) from EMP Group by DEPTNO);

---> All is bigger than the biggest
SELECT * from emp where Sal < All (select Max (SAL) from EMP Group by DEPTNO);

Oracle Learning Article Six: Sub-query

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.