经常涉及的Oracle面试题

冬宇酱_4718

冬宇酱_4718

2020-07-31

5557人浏览

转载

emp表

DEPT表:

觅游
觅游

觅游是一款AI学习资源工具,美团推出的 AI 原生 Agent 社区。

下载

工资等级表 salgrade

题目要求:根据Oracle数据库scott模式下的emp表和dept表,完成下列操作。

(1)查询20号部门的所有员工信息。
select * from emp where deptno = 20;
(2)查询所有工种为CLERK的员工的工号、员工名和部门名。
select empno,ename,deptno from emp where job like 'CLERK';
(3)查询奖金(COMM)高于工资(SAL)的员工信息。
select * from emp where comm > sal;
(4)查询奖金高于工资的20%的员工信息。
select * from emp where comm > (sal*0.2);
(5)查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息。
select * from emp 
where (deptno = 10 and job like 'MANAGER') or (deptno = 20 and job like 'CLERK');
(6)查询所有工种不是MANAGER和CLERK,且工资大于或等于2000的员工的详细信息。
select * from emp 
where job not in ('MANAGER','CLERK') and sal >= 2000 ;
(7)查询有奖金的员工的不同工种。
select distinct job from emp where comm is not null;
(8)查询所有员工工资和奖金的和。
select ename,(sal+nvl(comm,0)) salcomm from emp;
(9)查询没有奖金或奖金低于100的员工信息。
select * from emp where (comm is null or comm = 10 ;
(12)查询员工信息,要求以首字母大写的方式显示所有员工的姓名。
select upper(substr(ename,1,1)) || lower(substr(ename,2,length(ename)-1)) from emp;
(13)查询员工名正好为6个字符的员工的信息。
select * from emp where length(ename)= 6 ;
(14)查询员工名字中不包含字母“S”员工。
select * from emp where ename not in (select ename from emp where ename like '%S%') ;
select * from emp where ename not like ‘%S%’;
(15)查询员工姓名的第2个字母为“M”的员工信息。
select * from emp where ename like '_M%';
(16)查询所有员工姓名的前3个字符。
select substr(ename,1,3) from emp ;
(17)查询所有员工的姓名,如果包含字母“s”,则用“S”替换。
select replace(ename,'s','S') from emp ;
(18)查询员工的姓名和入职日期,并按入职日期从先到后进行排列。
select ename,hiredate from emp order by hiredate asc ;
(19)显示所有的姓名、工种、工资和奖金,按工种降序排列,若工种相同则按工资升序排列。
select ename,job,sal,comm from emp order by job desc,sal asc ;
(20)显示所有员工的姓名、入职的年份和月份,若入职日期所在的月份排序,若月份相同则按入职的年份排序。
select ename,to_char(hiredate,'yyyy')||'-'||to_char(hiredate,'mm') from emp order by to_char(hiredate,'mm'),to_char(hiredate,'yyyy');
(21)查询在2月份入职的所有员工信息。
select * from emp where to_char(hiredate,'mm') = 2 ;
(22)查询所有员工入职以来的工作期限,用“**年**月**日”的形式表示。
select ename,floor((sysdate-hiredate)/365)||'年'||floor(mod((sysdate-hiredate),365)/30)||'月'||cell(mod(mod((sysdate-hiredate),365),30))||'天' from emp ;
(23)查询至少有一个员工的部门信息。
select * from dept where deptno in (select distinct deptno from emp where mgr is not null) ;
(24)查询工资比SMITH员工工资高的所有员工信息。
select * from emp where sal > (select sal from emp where ename like 'SMITH') ;
(25)查询所有员工的姓名及其直接上级的姓名。
select staname,ename supname from (select ename staname,mgr from emp) t join emp on t.mgr=emp.empno ;
(26)查询入职日期早于其直接上级领导的所有员工信息。
select * from emp where empno in (select staempno from (select empno staempno,hiredate stahiredate,mgr from emp) t join emp on t.mgr=emp.empno and stahiredate  2500 ;
(31)查询最低工资低于2000的部门及其员工信息。
select * from emp where deptno in (select deptno from (select min(sal) min_sal,deptno from emp group by deptno) where min_sal  (select avg(sal) from emp) ;
(34)查询与SMITH员工从事相同工作的所有员工信息。
select * from emp where job in (select job from emp where ename like 'SMITH') and ename not like 'SMITH' ;
(35)列出工资等于30号部门中某个员工工资的所有员工的姓名和工资。
select ename,sal from emp where sal =any (select sal from emp where deptno = 30) ;
(36)查询工资高于30号部门中工作的所有员工的工资的员工姓名和工资。
select ename,sal from emp where sal >all (select sal from emp where deptno = 30) ;
(37)查询每个部门中的员工数量、平均工资和平均工作年限。
select dname,count,avg_sal,avg_date from dept join (select count(*) count,avg(sal) avg_sal,avg((sysdate-hiredate)/365) avg_date,deptno from emp group by deptno) t on dept.deptno = t.deptno ;
(38)查询从事同一种工作但不属于同一部门的员工信息。
select distinct t1.empno,t1.ename,t1.deptno from emp t1 join emp t2 on t1.job like t2.job and t1.deptno  t2.deptno ;
(39)查询各个部门的详细信息以及部门人数、部门平均工资。
Select dept.*,person_num,avg_sal from dept,(select count(*) person_num,avg(sal) avg_sal,deptno from emp group by deptno) t where dept.deptno = t.deptno ;
(40)查询各种工作的最低工资。
select job,min(sal) from emp group by job ;
(41)查询各个部门中的不同工种的最高工资。
select max(sal),job,deptno from emp group by deptno,job order by deptno,job ;
(42)查询10号部门员工以及领导的信息。
select * from emp where empno in (select mgr from emp where deptno=10) or deptno = 10 ;
(43)查询各个部门的人数及平均工资。
select deptno,count(*),avg(sal) from emp group by deptno ;
(44)查询工资为某个部门平均工资的员工信息。
select * from emp where sal in (select avg(sal) avg_sal from emp group by deptno) ;
(45)查询工资高于本部门平均工资的员工的信息。
select emp.* from emp join (select deptno,avg(sal) avg_sal from emp group by deptno) t on emp.deptno=t.deptno and sal>avg_sal ;
(46)查询工资高于本部门平均工资的员工的信息及其部门的平均工资。
select emp.*,	 from emp join (select deptno,avg(sal) avg_sal from emp group by deptno) t on emp.deptno=t.deptno and sal>avg_sal ;
(47)查询工资高于20号部门某个员工工资的员工的信息。
select * from emp where sal >any(select sal from emp where deptno=20);
(48)统计各个工种的人数与平均工资。
select job,count(*),avg(sal) from emp group by job ;
(49)统计每个部门中各个工种的人数与平均工资。
select deptno,job,count(*),avg(sal) from emp group by deptno,job order by deptno,job;
(50)查询工资、奖金与10 号部门某个员工工资、奖金都相同的员工的信息。
select emp.* from emp join (select sal,comm from emp where deptno = 10) t on emp.sal=t.sal and nvl(emp.comm,0)=nvl(t.comm,0) and emp.deptno != 10;
(51)查询部门人数大于5的部门的员工的信息。
select * from emp where deptno in (select deptno from emp group by deptno having count(*)>5);
(52)查询所有员工工资都大于1000的部门的信息。
select * from dept where deptno in (select distinct deptno from emp where deptno not in (select distinct deptno from emp where sal  (select max(sal) from (select e2.sal from emp e1 right join emp e2 on e1.mgr = e2.empno where e1.ename is null) t ); 

select ename from emp where empno in (select mgr from emp) and sal > 
(select max(sal) from emp where empno not in (select distinct mgr from emp where mgr is not null) );
//NOT IN遇到NULL则返回NULL,必须排除NULL值
 11. 求薪水最高的前5名雇员 
select empno,ename from (select * from emp order by sal desc) where rownum=6 and r(select count(*)-5 from emp);
【专题推荐】:2020年oracle面试题汇总(最新)

相关文章

PHP速学视频免费教程(入门到精通)
PHP速学视频免费教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
oracle清空表数据
oracle清空表数据

当表中的数据不需要时,则应该删除该数据并释放所占用的空间。本专题为大家提供oracle清空表数据的相关文章,帮助大家解决该问题。

2023.08.16

1201

5

Oracle中declare的使用
Oracle中declare的使用

Oracle DECLARE语句是PL/SQL编程语言中用于声明变量、常量、游标或异常的关键字。它的主要作用是在程序中定义这些对象,以便在后续的代码中使用。DECLARE语句的语法简单明了,可以根据需要声明多个对象。通过使用这些声明的对象,可以进行各种操作,如计算、查询数据库、处理异常等 。

2023.09.15

3613

5

oracle怎么分页
oracle怎么分页

实现分页的步骤:1、使用ROWNUM进行分页查询;2、在执行查询之前进行设置分页参数;3、使用"COUNT(*)"函数来获取总行数,并使用"CEIL"函数来向上取整计算总页数;4、在外部查询中使用"WHERE"子句来筛选出特定的行号范围,以实现分页查询。想了解更多oracle怎么分页的文章,可以来阅读本专题先的文章。

2023.09.18

3610

5

Oracle查看表操作历史记录
Oracle查看表操作历史记录

查看操作历史记录的方法:1、使用Oracle内置的审计功能,可以记录数据库中发生的各种操作,包括登录、DDL语句、DML语句等;2、使用Oracle日志文件,其中包含了数据库中发生的各种操作,可以通过查看日志文件来获取操作历史记录;3、使用Oracle的Flashback功能,可以查看数据库在某个时间点的操作历史记录;4、使用第三方工具等。本专题还提供其他查看表操作的文章,大家可以免费阅读。

2023.09.19

2069

3

Oracle中RAC的用法
Oracle中RAC的用法

Oracle中RAC的用法:1、通过在多个服务器上运行数据库实例来提供高可用性;2、允许在需要时增加或减少节点数量;3、通过将工作负载分布到多个节点上来实现负载均衡;4、使用共享存储来实现多个节点之间的数据共享;5、允许多个节点同时处理数据库请求,从而实现并行处理;6、提供了透明故障切换功能;7、使用了一些技术来确保数据的一致性;8、提供了管理工具来简化RAC环境的管理和维护。本专题还提供RAC相关的其他文章,大家可以免费阅读。

2023.09.19

2673

7

oracle imp
oracle imp

imp是Oracle数据库中的一个命令行工具,用于将导出的数据和对象从一个数据库实例导入到另一个数据库实例。imp命令的一般语法为“imp username/password@connect_string file=file_name [options]”。

2023.09.19

3769

4

常用的数据库软件
常用的数据库软件

常用的数据库软件有MySQL、Oracle、SQL Server、PostgreSQL、MongoDB、Redis、Cassandra、Hadoop、Spark和Amazon DynamoDB。更多关于数据库软件的内容详情请看本专题下面的文章。php中文网欢迎大家前来学习。

2023.11.02

5069

19

oracle通配符有哪些
oracle通配符有哪些

oracle通配符有“%”、“_”、“[]”和“[^]"。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2023.11.08

277

5

oracle四舍五入怎么操作
oracle四舍五入怎么操作

oracle四舍五入操作可以使用ROUND函数来实现,其语法为“ROUND(number, decimal_places)”,其中,number是要进行四舍五入的数值,decimal_places是指定的小数位数。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2023.11.14

986

5

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
热门推荐
/
最新课程
phpStudy极速入门视频教程
phpStudy极速入门视频教程

共6课时 | 54.7万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时 | 134.3万人学习