- 检索dept中所有的记录,并按部门名称排序。
create or replace view v1 as
select * from univ.dept order by dname;
- 列出工资(SAL)在15000到25000之间的所有员工的ENAME,SAL,并按ENAME排序。
create view V2 as
select ename,sal
from univ.emp
where sal between 15000 and 25000
order by ename;
- 显示DEPT表中的部门编号和部门名称,并按部门名称排序。
create or replace view V3 as
select deptno,dname
from univ.dept
order by dname;
- 显示所有不同的工作类型,并降序排序。
create or replace view v4 as
select distinct job from univ.emp order by job desc;
- 列出没有提成(comm)的所有职工的姓名与工资,并按姓名排序。
create view V5 as
select ename,sal
from univ.emp
where comm is null
order by ename;
- 列出部门编号是20,工作是“clerk”(办事员)的职工信息,并按姓名排序。
create view v6 as
select *
from univ.emp
where (job='clerk'and deptno=20)order by ename;
- 显示姓名中包含AR或IN的职工姓名,并按姓名排序。
create view v7 as
select ename
from univ.emp
where (ename like'%AR%' or ename like'%IN%')
order by ename;
- 显示姓名中包含AR和IN的职工姓名,并按姓名排序。
create view V8 as
select distinct ename
from univ.emp
where ename like '%AR%' and ename like '%IN%'
order by ename;
- 显示所有职工的姓名和各项收入总和(sal+comm),并按姓名排序。
create or replace view V9 as
select ename,sal+nvl(comm,0) as salcomm
from univ.emp
order by ename;
- 查询每个部门的平均工资(用round函数取整),并按部门编号排序。
create view v10
as select deptno, round(avg(sal)) "平均工资"
from univ.emp group by deptno;
- 查询出每个部门中工资最高的职工,并按部门编号排序。若同一部门有多个最高工资者,再按职工号排序。
create view V11 as
select *
from univ.emp
where sal in (select max(sal)
from univ.emp
group by deptno)
order by deptno,empno asc;
- 查询出每个部门比本部门平均工资高的职工人数,并按部门编号排序。
create or replace view V12 as
select a.deptno,count(*) as rs
from univ.emp a,(select deptno,avg(sal) avgsal from univ.emp group by deptno) b
where a.deptno=b.deptno and a.sal>b.avgsal group by a.deptno
order by deptno;
- 列出至少有一个职工的所有部门,并按部门编号排序。
create view v13 as
select deptno from univ.dept
where deptno in (select deptno from univ.emp group by deptno having count(deptno)>=1) order by deptno;
- 列出工资比“JONES”多的所有职工,并按职工编号排序。
create view v14 as
select * from univ.emp
where sal>(select sal from univ.emp where ename = 'JONES')
order by empno;
- 列出所有职工的姓名及其直接上级的姓名,并按职工姓名排序。
create or replace view V15 as
select distinct a.ename,
(select ename from univ.emp where univ.emp.empno=a.mgr) as manager
from univ.emp a
where mgr is not null
order by ename;
- 列出受雇日期早于其直接上级的所有职工,并按姓名排序。
create view v16 as
select * from univ.emp a
where a.hiredate<(select hiredate from univ.emp b where(b.empno=a.mgr)) order by a.ename;
- 列出部门名称和这些部门职工的编号、姓名,要求同时列出那些没有职工的部门,并按部门名称和职工编号排序。
create view V17 as
select dname,empno,ename
from univ.emp natural right outer join univ.dept
order by dname,empno;
- 列出所有办事员的姓名及其部门名称,并按姓名排序。
create view v18 as
select a.ename,b.dname from univ.emp a
left outer join univ.dept b
on a.deptno=b.deptno where job='clerk' order by a.ename;
- 列出最低工资大于35000的各种工作类型,并降序排序。
create view v19 as
select job from univ.emp where sal>35000 order by job desc;
- 列出在销售部(“sales”)工作的职工的姓名,并按姓名排序。
create view V20 as
select ename
from univ.emp natural join univ.dept
where dname='SALES'
order by ename;
- 列出工资高于公司平均工资的所有职工,并按姓名排序。
create or replace view V21 as
select ename,sal
from univ.emp
where sal>(select max(sal) from univ.emp where deptno=30)
order by ename;
- 列出与“SCOTT”从事相同工作的所有职工,并按姓名排序。
create view v22 as
select *
from univ.emp
where job=(select job from univ.emp where ename='SCOTT')
order by ename;
- 列出工资高于“30号部门的最高工资”的职工姓名和工资,并按姓名排序。
create or replace view V23 as
select ename,sal
from univ.emp
where sal>(select max(sal) from univ.emp where deptno=30)
order by ename;
- 列出工资高于在部门
create or replace view V24 as
select ename,sal
from univ.emp
where sal>(select max(sal) from univ.emp where deptno=30)
order by ename;
- 列出在每个部门工作的职工数量、平均工资(用round函数取整),并按部门编号排序。
create view v25 as
select deptno,count(*) numbe,round(avg(sal))as a_1 from univ.emp group by deptno order by deptno;
- 列出所有职工的姓名、部门名称和工资,并按姓名排序。
create view V26 as
select ename,dname,sal
from univ.emp natural join univ.dept
order by ename;
- 列出所有部门的详细信息和部门人数,并按部门编号排序。
create view V26 as
select ename,dname,sal
from univ.emp natural join univ.dept
order by ename;
- 列出职工中各种工作类型的最低工资,并按工作类型排序。
create or replace view v28 as
select job, min(sal) as min_sal from univ.emp group by job order by job;
- 列出各个部门的经理(“manager”)的最低工资。
create view V29 as
select min(sal) as min_sal
from univ.emp natural join univ.dept
where sal in(select sal from univ.emp where job='manager');
- 列出平均工资最高的部门的名称。
create or replace view v30 as
select dname
from univ.dept natural join univ.emp
group by dname
having avg(sal)>=all(select avg(sal)from univ.emp group by deptno);
- 列出不在北美工作职工的姓名,并按姓名排序。
create view v31 as
select e.ename from univ.dept d left outer join univ.countries c on (d.CID=c.CID)left join univ.emp e on(d.deptno=e.deptno)
where c.REGION !='North America'order by ename;