1、查询拥有员工的部门名、部门号。
select distinct d.dname, d.deptno from dept d,emp e where d.deptno = e.deptno;
2、查询工资水平多于smith的员工信息。
select *from emp where sal > (select sal from emp where ename = 'smith');
3、查询员工和所属经理的姓名。
(1)
select e.ename,m.ename from emp e
inner join emp m on e.mgr = m.empno;
(2)
select e.ename , m.ename from emp e , emp m where e.mgr = m.empno;
4、查询员工的入职日期早于其经理入职日期的,员工及其经理姓名。
(1)
select e.ename,m.ename from emp e
inner join emp m on e.mgr = m.empno
where e.hiredate < m.hiredate;
(2)
select e.ename,m.ename from emp e,emp m
where e.mgr=m.empno
and e.hiredate < m.hiredate;
5、查询员工姓名及其所在的部门名称。
(1)
select e.ename,d.dname from emp e inner join dept d on e.deptno = d.deptno;
(2)
select e.ename,d.dname from emp e , dept d where e.deptno = d.deptno;
6、查询从事clerk工作的员工姓名和所在部门名称。
select e.ename,d.dname
from emp e , dept d
where e.deptno = d.deptno and e.job = 'CLERK';
7、查询销售部(sales)所有员工的姓名。
(1)
select e.ename from emp e,dept d
where e.deptno = d.deptno and d.dname = 'sales';
(2)
· select ename from emp where deptno=(select deptno from dept where dname='sales');
8、查询与SCOTT从事相同工作的员工。
select * from emp
where job = (select job from emp where ename = 'scott');
9、查询与30部门员工工资水平相同的员工姓名与工资。
select ename,sal from emp
where sal in (select sal from emp where deptno = 30);
10、查询工资高于30部门所有员工工资水平的员工信息。
(1)
select * from emp
where sal > all(select sal from emp where deptno = 30);
(2)
select * from emp
where sal > (select max(sal) from emp where deptno = 30);
11、查询部门编号、部门名称、部门地址及其每个部门的员工总数。
select d.deptno,d.dname,d.loc,count(e.deptno)
from dept d,emp e
where d.deptno = e.deptno
group by e.deptno;
12、查询员工的姓名、所在部门名称及其工资。
select e.ename,d.dname,e.sal from emp e,dept d
where e.deptno = d.deptno;
13、查询员工的详细信息。(包括部门名称、地址)。
select e.* , d.dname,d.loc from emp e, dept d
where e.deptno = d.deptno;
14、查询工资处于第四级别的员工的姓名,工资。
(1)
select ename,sal from emp e ,salgrade s
where e.sal >= s.losal and e.sal <= s.hisal
and s.grade = 4;
(2)
select e.ename,e.sal from
emp e,(select losal,hisal from salgrade where grade=4) g where e.sal between g.losal and g.hisal;
·