oracle数据库基本知识面试题,Oracle数据库面试练习题

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;

30.查询出最早工作的那个人的名字、入职时间和薪水。

分析:最早工作人 — hiredate 最小值

select ename,hiredate,sal from emp where hiredate = (select min(hiredate) from emp);

select ename,hiredate,sal from emp where hiredate <= all(select hiredate from emp);

> any === > min

> all === > max

< any === < max

< all === < min

31.显示所有员工的名字、薪水、奖金,如果没有奖金,暂时显示100.

分析:select ename,sal,comm from emp; —- 没有奖金显示100  函数ifnull

select ename,sal,ifnull(comm,100) from emp;

32.显示出薪水最高人的职位。

分析: select job from emp where sal = (select max(sal) from emp);

select job from emp where sal >= all(select sal from emp);

33.查出emp表中所有部门的最高薪水和最低薪水,部门编号为10的部门不显示。

分析:按部门分组 select deptno,max(sal),min(sal) from emp where deptno<>10 group by deptno;

34.删除10号部门薪水最高的员工。

分析:delete from emp where deptno=10 and sal >= all(select sal from emp where deptno=10 ); // MYSQL 不支持

Mysql 规范,修改或者删除 表中记录,不允许在子查询中 查询相同表

ERROR 1093 (HY000): You can’t specify target table ‘emp’ for update in FROM clause

解决方案:临时表

delete from emp where deptno=10 and sal >= all(select t.sal from (select sal from emp where deptno=10) t );

35.将薪水最高的员工的薪水降30%。

分析:update emp set sal = sal*0.7 where sal = (select max(sal) from emp); // MYSQL 不支持

引入 临时表

update emp set sal = sal*0.7 where sal = (select t.maxsal  from (select max(sal) maxsal from emp) t);

36.查询员工姓名,工资和 工资级别(工资>=3000 为3级,工资>2000 为2级,工资<=2000 为1级)

分析:

select ename,sal, case when sal>=3000 then ‘3级’ when sal>2000 then ‘2级’ else ‘1级’ end 级别 from emp;

语法:case … when … then … when … then … else … end

行列互换

姓名 课程 分数

张三 语文 74

张三 数学 83

张三 物理 93

李四 语文 74

李四 数学 84

李四 物理 94

想变成(得到如下结果):

姓名 语文 数学 物理

—- —- —- —-

李四 74   84   94

张三 74   83   93

——————-

select name,max(case when cource =’语文’ then score else 0 end) from scores group by name;

select name,max(case when cource =’语文’ then score else 0 end)  语文,max(case when cource =’数学’ then score else 0 end) 数学,

max(case when cource =’英语’ then score else 0 end) 英语  from scores group by name;

22/2<12

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值