----高级查询-----创表createtable employee asselect * from scott.emp;
createtable department asselect * from scott.dept;
createtable salgrade asselect * from scott.salgrade;
--employee表结构
EMPNO NUMBER(4)
ENAME VARCHAR2(10) Y
JOB VARCHAR2(9) Y
MGR NUMBER(4) Y
HIREDATE DATE Y
SAL NUMBER(7,2) Y
COMM NUMBER(7,2) Y
DEPTNO NUMBER(2) Y
--deparment表结构
DEPTNO NUMBER(2)
DNAME VARCHAR2(14) Y
LOC VARCHAR2(13) Y
--salgrade表结构
GRADE NUMBER Y
LOSAL NUMBER Y
HISAL NUMBER Y
--32. 查询部门在‘NEW YORK’工资低于4000,不是‘CLERK’的员工?select * from employee e
leftjoin department d
on e.deptno = d.deptno
where sal<4000and job != 'CLERK'and loc ='NEW YORK'--33. 查询部门在‘CHICAGO’,在1981年入职,工资在2000~4000的员工?select * from employee e
leftjoin department d
on e.deptno = d.deptno
where sal between2000in4000and loc = 'CHICAGO'andextract( yearfrom hiredate) = 1981--34:查询员工及所在的部门信息(部门号,部门名,所在城市)select ename,e.deptno,dname,loc from employee e
leftjoin department d on e.deptno = d.deptno;
--35:查询在10号部门号的员工及部门信息(部门号,部门名,所在城市)select ename,e.deptno,dname,loc from employee e
leftjoin department d on e.deptno = d.deptno
where e.deptno = 10--36:查询工资低于3000,工作是clerk和salman,部门在"芝加哥”的员工基本信息和员工的部门信息。select e.*,,d.dname,d.loc
from employee e
leftjoin department d on e.deptno = d.deptno
where sal <3000and (job ='CLERK'or job = 'SALMAN') and loc ='CHICAGO'/*
37: 问题:查看每个员工的工资等级情况
1等级-->显示为:临时工
2等级-->显示为:苦力工
3等级-->??
*/select e.*,decode(grade,1,'苦力',2,'临时工','其他')from employee e,salgrade
where sal between losal and hisal
-- 38.查询有上级领导的员工信息以及他的上级领导的信息。显示为:谁(工人)为谁(上级)工作select e.name 员工,boss.name 上司 from employee e,employee boss
where e.mgr = boss.empno