Oracle database Query statements

Source: Internet
Author: User

Write the SQL statement for the following query, using the EMP and dept tables of the Scott user as the query data:

1. List all departments that have at least one employee.

SQL statements:

Select *  from SCOTT. DEPTwherein(Selectdistinct from SCOTT. DEPT);

Query Result:

2. Lists the names of all employees and their immediate superiors.

SQL statements:

Select E.ename Employee name, M.ename Superior name  from scott.emp e,scott.emp m where m.empno=e.mgr;

Query Result:

3. Lists the department names and employee information for those departments, and lists the departments that have no employees.

SQL statements:

Select d.dname,e.* from scott.dept d,scott.emp ewhere d.deptno= E.deptno (+);

Query Result:

4. Lists various jobs with a minimum salary of more than 1500.

SQL statements:

Select Job,min(sal) Minimum salary  from SCOTT. EMPGroup by jobhavemin(sal)>;

Query Result:

5. List all employees who pay more than the company's average salary.

SQL statements:

Select *  from SCOTT. EMPwhere  sal>(Selectavg from SCOTT. EMP);

Query Result:

6. Lists the names and salaries of all employees whose salaries are equal to the salaries of employees in department 30.

SQL statements:

Select Ename,sal,deptno  from SCOTT. EMPwhere in (selectfromwhere deptno=);

Query Result:

Oracle database Query statements

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.