Oracle查询语句面试题

Oracle查询语句面试题

01. 查询员工表所有数据,并说明使用*的缺点 select * from emp; 01.查询职(job)为

 查询员工表所有数据,并说明使用*的缺点

select * from emp;

登录后复制

查询职(job)为’PRESIDENT’的员工的工资

select sal from emp where job='PRESIDENT';

登录后复制

【专题推荐】:2020年oracle面试题汇总(最新)

02.查询佣金为0或为null的员工的信息

select * from emp where comm is null or comm=1;

登录后复制

03.查询入职日期在1981-5-1到1981-12-31之间的所有员工的信息

select * from emp where hiredate between to_date(‘1-5月-81’) and to_date(‘31-12月-81’)

登录后复制

04..查询所有名字长度为4的员工的员工的编号,姓名

select empno,ename from emp where length(ename)=4

登录后复制

05.显示10号部门饿所有经理和20号部门的所有员工

select * from emp where job='MANAGER' and deptno=10 or job='CLERK' and deptno=20;

登录后复制

06.显示姓名没有’L’字的员工的详细信息或含有’SM’字的员工信息

select * from emp where ename not like '%L%' or ename like '%SM%';

登录后复制

07.显示各个部门经理的工资

select deptno,sal from emp where job='MANAGER';

登录后复制

08.显示佣金收入比工资高的员工的详细信息

select * from emp where comm>sal;

登录后复制

10.把hiredate列看做是员工的生日,求本月过生日的员工:

SQL> select * from empwhere to_char(hiredate,'mm')=to_char(sysdate,'mm');

登录后复制

11.把hiredate列看做是员工的生日,求下月过生日的员工

SQL> select * from empwhere to_char(hiredate,'mm')=to_char(add_months(sysdate,1),'mm');

登录后复制

12.求1982年入职的员工

SQL> select * from emp where to_char(hiredate,'yyyy')='1982';

登录后复制

hiredate是date类型的,1982是字符串类型的,类型匹配才可以

13.求1981年下半年入职的员工

select * from empwhere hiredate between to_date('1981-7-1','yyyy-mm-dd')and to_date('1982-1-1','yyyy-mm-dd')-1;

登录后复制

注:to_char()函数和to_date()函数

to_char()函数是把日期的类型转换为指定的格式

to_date()是把字符串转换为日期类型

-1的原因是更精确

14.求1981年各个月入职的员工个数

SQL> select to_char(hiredate,'mm'),count(*) from emp where to_char(hiredate,'yyyy')='1981' group by to_char(hiredate,'mm') order by to_char(hiredate,'mm');

登录后复制

select to_char(hiredate,'mm'),count(*) from emp where to_char(hiredate,'yyyy')='1981' group by to_char(hiredate,'mm') order by to_char(hiredate,'mm');

登录后复制

PartII

01 .查询各个部门的平均工资

SQL> select deptno,avg(nvl(sal,0)) from emp group by deptno;

登录后复制

02.显示各种职位的最低工资

SQL> select job,min(sal) from emp group by job;

登录后复制

03.按照入职日期由新到旧排列员工信息

SQL> select hiredate from emp order by hiredate desc;

登录后复制

04.查询员工的基本信息,附加其上级的姓名(自关联)

SQL> select e.*,e1.ename from emp e,emp e1 where e.mgr=e1.empno;

登录后复制

05.显示工资比’ALLEN’高的所有员工的姓名和工作

SQL> select ename,sal from emp where sal>(select sal from emp where ename='ALLEN');

登录后复制

06.显示与scott从事相同工作的员工的信息(子查询)

SQL> select * from emp where job=(select job from emp where ename='SCOTT');

登录后复制

07.显示销售部(‘SALES’)员工的姓名

SQL> select e.ename from emp e inner join dept d on e.deptno=d.deptno where d.dname='SALES';

登录后复制

08.显示与30号门’MARTIN’员工工资相同的员工的姓名和工资

SQL> select ename,sal from emp where sal=(select sal from emp where deptno=30 and ename='MARTIN');

登录后复制

09.查询所有工资高于平均工资(包括所有员工)的销售人员

SQL> select * from emp where sal>(select avg(sal) from emp) and job='SALESMAN';

登录后复制

SQL> select * from emp where job='SALESMAN' and sal>(select avg(sal) from emp);

登录后复制

10.显示所有职员的姓名及其所在部门的名称和工资(表连接)

SQL> select e.*,e.sal,d.dname from emp e inner join dept d on e.deptno=d.deptno;

登录后复制

11.查询在研发部(RESEARCH)工作人员的编号,姓名,,工作部门,工作所在地

SQL> select e.empno,e.ename,d.dname,d.loc from emp e inner join dept d on e.deptno=d.deptno where dname='RESEARCH';

登录后复制

12.查询各个部门的名称和员工人数

select e.deptno,d.dname,count(*) from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname

登录后复制

分析:

SQL> select d.dname from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;DNAME--------------ACCOUNTINGRESEARCHSALESSQL> select e.deptno,d.dname from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;DEPTNO DNAME------ --------------10 ACCOUNTING20 RESEARCH30 SALESSQL> select e.deptno,d.dname,count(*) from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;DEPTNO DNAME COUNT(*)------ -------------- ----------10 ACCOUNTING 3

登录后复制

13.查询各个部门员工工资大于平均工资(平均工资包括所有员工)的人数和员工职位(子查询)

SQL> select count(*),job from emp where sal>(select avg(sal) from emp) group by job;

登录后复制

14.查询工资相同的员工的工资和姓名(子查询)

SQL> select sal,ename from emp e where(select count(*) from emp where sal=e.sal group by sal)>1;

登录后复制

SQL> select e.sal,e.ename from emp e,emp e1 where e.sal=e1.sal and e.enamee1.ename;

登录后复制

相关学习推荐:oracle数据库学习教程

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/1932474.html

(0)
上一篇 2025年2月22日 21:54:14
下一篇 2025年2月22日 21:54:32

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • Oracle 数据库开发面试题

    当我们执行delete操作时所有表数据先被copy到回滚表空间,数据量不同花费时间长短不一。而truncate是直接删除数据不进回滚表空间 【专题推荐】:2020年oracle面试题汇总(最新) 最近参加了数场面试,总结一下竞聘Oracle…

    2025年2月23日
    100
  • Oracle面试题及答案整理

    1、表:table1(FId,Fclass,Fscore),用最高效最简单的SQL列出各班成绩最高的列表,显示班级,成绩两个字段。 select fclass,max(f 表:table1(FId,Fclass,Fscore),用最高效最简…

    2025年2月23日
    100
  • 经典Oracle面试题目

    ORACLE是ORACLE公司的数据产品,支持海量数据存储,支持分布式布暑,支持多用户,跨平台,数据安全完整性控制性能优越,是一个OR 1、对数据库SQL2005、Oracle熟悉吗? SQL2005是微软公司的数据库产品。是一个RDBMS…

    2025年2月22日
    200

发表回复

登录后才能评论