Oracle数据库查询语句

编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据:

1.列出至少有一个员工的所有部门。

SQL语句:

select * from SCOTT.DEPT
where deptno in
(select distinct deptno from SCOTT.DEPT);

查询结果:

Oracle数据库查询语句

2.列出所有员工的姓名及其直接上级的姓名。

SQL语句:

select e.ename 员工姓名,m.ename 上级姓名
from scott.emp e,scott.emp m
where m.empno=e.mgr;

查询结果:

Oracle数据库查询语句

3.列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门。

SQL语句:

select d.dname,e.*
from scott.dept d,scott.emp e
where d.deptno=e.deptno(+);

查询结果:

Oracle数据库查询语句

4.列出最低薪金大于1500 的各种工作。

SQL语句:

select job 工作,min(sal) 最低薪金
from SCOTT.EMP
group by job
having min(sal)>1500;

查询结果:

Oracle数据库查询语句

5.列出薪金高于公司平均薪金的所有员工。

SQL语句:

select *
from SCOTT.EMP
where  sal>(select avg(sal) from SCOTT.EMP);

查询结果:

Oracle数据库查询语句

6.列出薪金等于部门30 中员工的薪金的所有员工的姓名和薪金。

SQL语句:

select ename,sal,deptno
from SCOTT.EMP
where sal in (select sal from SCOTT.EMP where deptno=30);

查询结果:

Oracle数据库查询语句