oracle day08时间安排:
目标:子查询。
上节重点回顾:
1. 组函数。
2. group by
3. rowid
授课内容:第一部分:子查询。
-第一部分:子查询。
select salary from employees where first_name = diana' ;4200.00
select * from employees where salary > 4200;
-子查询(单行子查询:子查询返回的结果只有一行数据)
select * from employees
where salary >(
select salary from employees where first_name = diana');
-显示和(雇员151从事相同工作)并且(工资大于雇员123的)雇员的姓名和工作。
select * from employees
where job_id = select job_id from employees where employee_id = 151)
and salary > select salary from employees where employee_id = 123);
-显示工资最低的雇员的姓名、工作、和工资。
select * from employees
where salary = select min(salary) from employees);
-(难点)显示【部门内最低工资】比【100部门最低工资要高】的部门编号。
-以及部门内最低工资。
select department_id,min(salary) from employees
group by department_id
h**ing min(salary) >select min(salary) from employees
where department_id = 100);
-查询工资与【任何一个部门最低工资】相等的雇员姓名,工资。
select * from employees where salary in
select min(salary) from employees
group by department_id);
-显示只要比【某个it工资低】但又【不是it工作】的雇员姓名,职位id,工资。
select * from employees
where salary < any (select salary from employees where job_id like 'it%')
and job_id <>it_prog';
-显示只要比【全部it工资低】但又【不是it工作】的雇员姓名,职位id,工资。
select * from employees
where salary < all (select salary from employees where job_id like 'it%')
and job_id <>it_prog';
-单列单行
-单列多行。
-多列单行。
-查询显示和adam同部门且同工作岗位的员工姓名、工作岗位、工资、部门编号。
select * from employees
where (department_id,job_id) =select department_id,job_id from employees where first_name = adam')
-多列多行。
-查询显示和steven同部门且同工作岗位的员工姓名、工作岗位、工资、部门编号。
select * from employees
where (department_id,job_id) in(
select department_id,job_id from employees where first_name = steven');
第二部分:集合。
-第二部分集合。
-工资大于4000的数据。
select * from employees where salary > 4000;
-部门是90的员工信息。
select * from employees where department_id = 90;
-取两个集合的并集。
-union 66
select * from employees where salary > 4000
unionselect * from employees where department_id = 90;
-union all 69
select * from employees where salary > 4000
union all
select * from employees where department_id = 90;
-intersect
select * from employees where salary > 4000
intersect
select * from employees where department_id = 90;
- 取差集(minus)
select * from employees where salary > 4000
minusselect * from employees where department_id = 90;
-集合取交集,并集,差集要求字段类型和个数必须完全一致(并不要求字段完全一致,可以是不同的表)
select employee_id,last_name,first_name,salary,job_id from employees where salary > 4000
unionselect employee_id,first_name,last_name,salary,job_id from employees where department_id = 90;
-查询的是工作为ad_vp salary+100 it_prog salary + 200
select job_id,salary, decode(job_id,upper('ad_vp'),salary+100,upper('it_prog') salary+200,salary)
from where job_id in( upper('ad_vp'),upper('it_prog'))
select job_id,salary,salary + 100 from employees where job_id = upper('ad_vp')
unionselect job_id,salary,salary + 200 from employees where job_id = upper('it_prog')
oracle笔记
1 查看表的结构 desc tabledescription 2 set timing on 打开操作表的时间记录。3 消除重复行 distinct 4 大小写不区分的是列名,而不是里面的数据。1 可以对某一列直接进行加减乘除。两列相加。2 如果有一列为null,所得结果也为空。使用nvl函数处理n...
Oracle笔记
第1页1.oracle 的使用 1.1.sqlplus 的命令 初始化表的位置 set nls lang american 设置编码才可以使用下面脚本 cd oracle home rdbms cd demo 我们目前使用的是oralce 9i 9201 版本 select from v versi...
oracle笔记
clear 清屏。col title for a20 设置title的字符最多有20个。oracle介绍。rdbsrdb 基本的存储结构是,二维表。表头。行。列。字段。sql的分类 dsl 关键字 select dml 操作 insert delete update ddl 定义 create dr...