--1.列出至少有三个员工的所有部门和部门信息。
select d.* from dept d,
(select e.deptno, count(1) n from emp e group by e.deptno) t
where d.deptno=t.deptno and t.n>=3;
--2.列出受雇日期早于直接上级的所有员工的编号,姓名,部门名称
select emp_table.empno, emp_table.ename, emp_dept.dname
from emp emp_table, emp mgr_table, dept emp_dept
where emp_table.mgr=mgr_table.empno
and emp_table.deptno=emp_dept.deptno
and emp_table.hiredate>mgr_table.hiredate;
--3.列出职位为“CLERK”的姓名和部门名称,部门人数:
select e.ename, d.dname, t.n
from emp e,
dept d,
(select deptno, count(1) n from emp group by deptno) t
where e.job='CLERK' --确定职位为“CLERK”
and e.deptno=d.deptno
and e.deptno=t.deptno;
--4.列出和“SCOTT”从事相同工作的所有员工及部门名称:
select e.*, d.dname
from emp e, dept d
where e.job=(select job from emp where ename='SCOTT')
and e.deptno=d.deptno;
--5.列出每个部门工作的员工数量、平均工资和平均服务期限(单位为年)
select e.deptno,
Oracle 常用的复杂查询语句
最新推荐文章于 2023-09-06 11:38:00 发布