赞
踩
oracle的常见面试题,仅供大家参考
前两天我做了一些oracle的面试题,觉得挺不错的,难易程度中等,今天总结了一下,仅供大家参考和学习。以下就是我做的面试题,大家可以看看。如果有什么不懂的给我留言,我们可以互相交流,互相讨论。共同进步,共同学习。
我给大家列一下emp和dept这两张表,表如下:
- SQL> select * from emp;
-
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
- ----- ---------- --------- ----- ----------- --------- --------- ------
- 7369 SMITH CLERK 7902 1980-12-17 800.00 20
- 7499 ALLEN SALESMAN 7698 1981-2-20 1600.00 300.00 30
- 7521 WARD SALESMAN 7698 1981-2-22 1250.00 500.00 30
- 7566 JONES MANAGER 7839 1981-4-2 2975.00 20
- 7654 MARTIN SALESMAN 7698 1981-9-28 1250.00 1400.00 30
- 7698 BLAKE MANAGER 7839 1981-5-1 2850.00 30
- 7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
- 7788 SCOTT ANALYST 7566 1982-12-9 3000.00 20
- 7839 KING PRESIDENT 1981-11-17 5000.00 10
- 7844 TURNER SALESMAN 7698 1981-9-8 1500.00 0.00 30
- 7876 ADAMS CLERK 7788 1983-1-12 1100.00 20
- 7900 JAMES CLERK 7698 1981-12-3 950.00 30
- 7902 FORD ANALYST 7566 1981-12-3 3000.00 20
- 7934 MILLER CLERK 7782 1982-1-23 1300.00 10
-
- 14 rows selected
-
- SQL> select * from dept;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 10 ACCOUNTING NEW YORK
- 20 RESEARCH DALLAS
- 30 SALES CHICAGO
- 40 OPERATIONS BOSTON
01.查询员工表所有数据,并说明使用*的缺点
select * from emp;
使用“*”效率不高
02.查询职位(JOB)为'PRESIDENT'的员工的工资
select sal from emp where job='PRESIDENT';
03.查询佣金(COMM)为0或为NULL的员工信息
select * from emp where comm is null or comm=0;
04.查询入职日期在1982-5-1到1981-12-31之间的所有员工信息
select * from emp where hiredate between to_date('1981-05-01','YYYY-MM-DD') and to_date('1981-12-31','YYYY-MM-DD');
05.查询所有名字长度为4的员工的员工编号,姓名
select empno,ename from emp where length(ename)=4;
06.显示10号部门的所有经理('MANAGER')和20号部门的所有职员('CLERK')的详细信息
select * from emp where deptno=10 and job='MANAGER' or deptno=20 and job='CLERK';
07.显示姓名中没有'L'字的员工的详细信息或含有'SM'字的员工信息
select * from emp where ename not like '%L%' or ename like '%SM%';
08.显示各个部门经理('MANAGER')的工资
select sal from emp where job='MANAGER';
09.显示佣金(COMM)收入比工资(SAL)高的员工的详细信息
select * from emp where comm>sal;
10.把hiredate列看做是员工的生日,求本月过生日的员工(考察知识点:单行函数)
select * from emp where to_char(hiredate,'mm')=to_char(sysdate,'mm');
11.把hiredate列看做是员工的生日,求下月过生日的员工(考察知识点:单行函数)
select * from emp where to_char(hiredate,'mm')=to_char(add_months(sysdate,1),'mm');
12.求1982年入职的员工(考察知识点:单行函数)
select * from emp where hiredate between to_date('1982-01-01','YYYY-MM-DD') and to_date('1982-12-31','YYYY-MM-DD');
--------等效于---------->
select * from emp where to_char(hiredate,'yyyy')='1982';
13.求1981年下半年入职的员工(考察知识点:单行函数)
select * from emp where hiredate between to_date('1981-07-01','YYYY-MM-DD') and to_date('1981-12-31','YYYY-MM-DD');
14.求1981年各个月入职的员工个数(考察知识点:组函数)
select count(*),to_char(trunc(hiredate,'month'),'YYYY-MM-DD') from emp where to_char(hiredate,'yyyy')='1981' group by trunc(hiredate,'month');
15.查询各个部门的平均工资
select avg(nvl(sal,0)),deptno from emp group by deptno;
16.显示各种职位的最低工资
select job,min(nvl(sal,0)) from emp group by job;
17.按照入职日期由新到旧排列员工信息
select * from emp order by hiredate desc;
18.查询员工的基本信息,附加其上级的姓名
select e.*,e1.ename as "上级的姓名" from emp e inner join emp e1 on e.mgr=e1.empno;
-------等效于--------->
select e.*,e1.ename from emp e,emp e1 where e.mgr=e1.empno;
19.显示工资比'ALLEN'高的所有员工的姓名和工资
select ename,sal from emp where sal>(select sal from emp where ename='ALLEN');
20.显示与'SCOTT'从事相同工作的员工的详细信息
select * from emp where job=(select job from emp where ename='SCOTT');
21.显示销售部('SALESMAN')员工的姓名
select ename from emp e,dept d where e.deptno=d.deptno and d.dname='SALESMAN';
22.显示与30号部门'MARTIN'员工工资相同的员工的姓名和工资
select ename,sal from emp where sal=(select sal from emp where ename='MARTIN' and deptno=30);
23.查询所有工资高于平均工资的销售人员('SALESMAN')
select * from emp where job='SALESMAN' and sal>(select nvl(sal,0) from emp);
24.显示所有职员的姓名及其所在部门的名称和工资
select ename,dname as "部门名称",sal from emp e inner join dept d on e.deptno=d.deptno;
25查询在研发部('RESEARCH')工作员工的编号,姓名,工作部门,工作所在地
select empno,ename,dname,loc from emp,dept where emp.deptno=dept.deptno and dname='RESEARCH';
26.查询各个部门的名称和员工人数
select * from (select deptno,count(*) from emp group by deptno) e inner join dept on e.deptno=dept.deptno;
27.查询各个职位员工工资大于平均工资(平均工资包括所有员工)的人数和员工职位
select count(*),job from emp where sal>(select avg(sal) from emp) group by job;
28.查询工资相同的员工的工资和姓名
select * from emp e where (select count(*) from emp where sal=e.sal group by sal)>1;
29.查询工资最高的3名员工信息
select * from (select * from emp order by sal desc) where rownum<=3;
30.按工资进行排名,排名从1开始,工资相同排名相同(如果两人并列第1则没有第2名,从第3名继续排)
select e.*,(select count(*) from emp where sal>e.sal)+1 rank from emp e order by rank;
31.求入职日期相同的(年月日相同)的员工
select * from emp e where (select count(*) from emp where e.hiredate=hiredate)>1;
32.查询每个部门的最高工资
select deptno,max(sal) from emp group by deptno order by deptno;
33.查询每个部门,每种职位的最高工资
select deptno,job,max(sal) from emp group by deptno,job order by deptno,job;
34.查询每个部门有多少人
select deptno,count(*) from emp group by deptno;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。