多表查询


一 语句查询


1,  在SCOTT模式下,检索emp表的指定列(empno,ename,job)


2,  检索emp表的sal列,把其值调整为原来的1.5


3,  在emp表中,使用like关键字匹配以字母s开头的员工名称


4,  查询emp表中没有奖金的员工信息


5,  在emp表中,查询既不是最高工资,也不是最低工资的员工信息


6,  在emp表中,查询不是销售部门的员工信息


7,  在emp表中,查询工资大于部门编号为10的任意一个员工工资的其他部门的员工信息


8,  在emp表中,使用关联子查询检索工资大于同职位的平均工资的员工信息


二 仿写题(读完再写)


根据提示的函数来完成任务


 提示:字符串函数(大小写转换)


ABC转换为abc   lower函数  select  lower(‘ABC’)  from dual;


abc转换ABC    upper函数   select  upper(‘abc’)  from dual;


完成  ASCII码值和数字之间的转换:


数字转换为ASCII码值: chr


求出 67 对应多少 68 , 66 ,18 , 37 ,28  ,97 分别对应什么字符


 


ASCII码值转换为数字  :ascii


‘Z’  ‘?’   ‘!’  ‘a’  ‘A’


select ascii('Z') from dual;


 


三 查询题


 


字段


company


公司名(cname)

 编号(id)

LS

6

DG

9

GR

19


 


Employeehire


公司(id)

人数(num)

Fisq(财季)

6

2

1

9

2

4

19

4

1


 


(注释: 其中 公司名 人数nmuber为招聘人数 Employeehire为招聘表 )


  1. 将上述表结构分别创建两个表;
  2. 插入上述的数据;
  3. 向company表中插入一个新公司JZ 编号为29;
  4. 修改 Employeehire 表中的GR公司的数据改为在第一财季招聘人数为3。
  5. 求第四财季招聘过员工的公司名称

用户名Scott 密码tiger
select * from emp; --展示表结构 desc emp; --字段查询 select ename,sal from emp; select ename,empno from emp; select ename,hiredate ,sal,comm from emp; select ename,job,sal from emp; select ename,mgr,deptno from emp; --更改语句 --给所有人涨10%工资 select ename ,sal from emp; update emp set sal=sal*1.1; --领导说不能涨 rollback; select ename,sal from emp; --换种方案涨工资 --大于2000的涨20%,小于2000的涨10% update emp set sal=sal*1.2 where sal>2000; update emp set sal=sal*1.1 where sal<2000; --永久生效,不能更改 commit; --distinct 去除重复列 select ename ,job from emp; select distinct job from emp; select distinct deptno from emp; select distinct mgr from emp; --% 通配符 --查询首字母为a的员工信息 select * from emp where ename like 'A%'; --查询第二个字母为a的员工信息 select * from emp where ename like '_A%'; --查询第三个字母为a的员工信息 select * from emp where ename like '__A%'; --查询第四个字母为a 的员工信息 select * from emp where ename like '___A%'; --查询有a的员工 select * from emp where ename like '%A%'; --查询没有a的员工姓名 select ename from emp where ename not like '%A%'; --员工编号empno出现9的员工 select * from emp where empno like '&9&'; --上司编号mgr 出现8的姓名 select * from emp where mgr like '&8&'; --员工姓名ename出现s的员工的姓名 select * from emp where ename like '&s&'; --处理空值null select ename ,comm from emp where comm is not null; select ename,comm from emp where comm is null; select ename 姓名 ,nvl(comm,100)+sal*13 年薪 from emp; --p144,6.46-6.54 select deptno,count(*),sum(sal) from emp GROUP BY deptno; select job ,count(*),avg(sal) from emp where deptno=20 GROUP BY job having avg(sal)>1000; select * from emp,dept; select * from emp e,dept d where e.deptno=d.deptno; select empno ,sal ,s.* from emp e, salgrade s where sal between s.losal and s.hisal; select e.empno,e.ename,e.mgr ,b.empno,b.ename from emp e,emp b where e.mgr =b.empno; select * from emp e left join dept d on e.deptno =d.deptno; select * from emp e right join dept d on e.deptno =d.deptno; select * from emp e full join dept d on e.deptno=d.deptno; --1平均工资,最低工资,最高工资 --job分类 平均工资,最低工资,最高工资 select * deptno,count(*),sum(sal) from emp group by deptno; select job,count(*),avg(sal) from emp group by job; select job,count(*),min(sal) from emp group by job; select job,count(*),max(sal) from emp group by job; --having的用法 select job ,count(*),avg(sal) from emp group by job having avg(sal)>2000; --多表连接 select distinct e2.ename 上司的名字 from emp e1,emp e2 where e1.mgr=e2.mgr;
一 语句查询
1,    在SCOTT模式下,检索emp表的指定列(empno,ename,job)
2,    检索emp表的sal列,把其值调整为原来的1.5
3,    在emp表中,使用like关键字匹配以字母s开头的员工名称
4,    查询emp表中没有奖金的员工信息
5,    在emp表中,查询既不是最高工资,也不是最低工资的员工信息
6,    在emp表中,查询不是销售部门的员工信息
7,    在emp表中,查询工资大于部门编号为10的任意一个员工工资的其他部门的员工信息
8,    在emp表中,使用关联子查询检索工资大于同职位的平均工资的员工信息

select empno,ename,job from emp;

update emp set sal=sal * 1.1;

select * from emp where ename like 'S%';

select * from emp where comm is null;

select empno,ename,sal from emp where sal<(select max(sal)from emp) and sal >(select min(sal) from emp); 

select * from emp where deptno<>30;

select deptno ,ename,sal,from emp where sal> any(select sal from emp where deptno=10 ) and deptno<>10;

select deptno ,enam,sal from emp f where sal>(salect avg(sal) from emp where job=f.job) group by job;
二 仿写题(读完再写)
根据提示的函数来完成任务
 提示:字符串函数(大小写转换)
ABC转换为abc   lower函数  select  lower(‘ABC’)  from dual;
abc转换ABC    upper函数   select  upper(‘abc’)  from dual;
完成  ASCII码值和数字之间的转换:
数字转换为ASCII码值: chr 
求出 67 对应多少 686618372897 分别对应什么字符

select chr('68') from dual;
select chr('66') from dual;
select chr('18') from dual;
select chr('37') from dual;
select chr('28') from dual;
select chr('97') from dual;


ASCII码值转换为数字  :ascii
‘Z’  ‘?’   ‘!’  ‘a’  ‘A’
select ascii('Z') from dual;

三 查询题 

字段 
company
公司名(cname)     编号(id)
LS    6
DG    9
GR    19

Employeehire
公司(id)    人数(num)    Fisq(财季)
6    2    1
9    2    4
19    4    1

(注释: 其中 公司名 人数nmuber为招聘人数 Employeehire为招聘表 )
1.    将上述表结构分别创建两个表;
2.    插入上述的数据;
3.    向company表中插入一个新公司JZ 编号为29;
4.    修改 Employeehire 表中的GR公司的数据改为在第一财季招聘人数为3。
5.    求第四财季招聘过员工的公司名称

 

posted @ 2024-04-09 22:38  困到很想醒  阅读(10)  评论(0编辑  收藏  举报