oracle数据库课后题答案,Oracle数据库面试练习题及答案汇总(2)

12.列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金。

分析:

select * from emp where sal > all(select sal from emp where deptno = 30);

select * from emp where sal > (select max(sal) from emp where deptno = 30);

13.列出在每个部门工作的员工数量、平均工资。

分析:按部门分组

select deptno, count(*),avg(sal) from emp group by deptno;

14.列出所有员工的姓名、部门名称和工资。

分析:

select emp.ename,dept.dname,emp.sal from emp,dept where emp.deptno = dept.deptno;

15.列出所有部门的详细信息和部门人数。

分析:

select dept.*,count(emp.*) from emp,dept where emp.deptno = dept.deptno group by deptno ; 错误!

求各个部门编号和人数 select deptno,count(*) from emp group by deptno;

再和dept表关联 select dept.*,temp.部门人数 from dept , (select deptno,count(*) 部门人数 from emp group by deptno) temp where dept.deptno = temp.deptno ;

16.列出各种工作的最低工资。

分析:各个工作 分组 , 最低工资 min

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

17.列出各个部门的MANAGER(经理)的最低薪金。

分析:where job=’MANAGER’ 过滤所有不是经理数据

select deptno,min(sal) from emp where job =’MANAGER’ group by deptno;

18.列出所有员工的年工资,按年薪从低到高排序。

分析: select ename, sal*12 from emp order by sal*12 asc;

19.查出emp表中薪水在3000以上(包括3000)的所有员工的员工号、姓名、薪水。

分析: select * from emp where sal >= 3000;

20.查询出所有薪水在’ALLEN’之上的所有人员信息。

分析:select * from emp where sal > (select sal from emp where ename =’ALLEN’);

21.查询出emp表中部门编号为20,薪水在2000以上(不包括2000)的所有员工,显示他们的员工号,姓名以及薪水,以如下列名显示:员工编号 员工名字 薪水

分析: select empno 员工编号,ename 员工姓名 ,sal 薪水 from emp where deptno = 20 and sal > 2000;

22.查询出emp表中所有的工作种类(无重复)

分析: select distinct job from emp;

23.查询出所有奖金(comm)字段不为空的人员的所有信息。

分析:不为空 is not null

select * from emp where comm is not null;

24.查询出薪水在800到2500之间(闭区间)所有员工的信息。(注:使用两种方式实现and以及between and)

分析:select * from emp where sal >= 800 and sal <= 2500;

select * from emp where sal between 800 and 2500;

25.查询出员工号为7521,7900,7782的所有员工的信息。(注:使用两种方式实现,or以及in)

分析:select * from emp where empno in(7521,7900,7782);

select * from emp where empno=7521 or empno = 7900 or empno = 7782;

26.查询出名字中有“A”字符,并且薪水在1000以上(不包括1000)的所有员工信息。

分析: 模糊查询

select * from emp where ename like ‘%A%’ and sal > 1000;

27.查询出名字第三个字母是“M”的所有员工信息。

分析:第三个字母 __M%

select * from emp where ename like ‘__M%’;

28.将所有员工按薪水升序排序,薪水相同的按照入职时间降序排序。

分析:select * from emp order by sal asc,hiredate desc;

29.将所有员工按照名字首字母升序排序,首字母相同的按照薪水降序排序。

分析:SUBSTRING(‘字符串’,第几个字符,长度); —- 首字母 substring(ename,1,1)

select * from emp order by substring(ename,1,1) asc,sal desc;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值