tsm_department :部门表
tsm_employee:雇员表
--1、根据部门编码查询雇员的名称、雇员的职位、雇员的电话。
select * from tsm_employee where dept_no=
(select dept_no from tsm_department where dept_name='软件开发87部')
--2、查询所有项目经理的姓名、雇员编号以及对应的部门名称。
select emp_no,name,position,
dept_no,
(select dept_name from tsm_department d where d.dept_no=e.dept_no) dept_name
from tsm_employee e
where position='项目经理'
--3、找出佣金高于薪金的雇员,列出雇员姓名,职位,佣金和薪水
select * from tsm_employee where
commision >salary
--4、找出佣金高于 薪金60%的雇员, 列出雇员姓名,职位,佣金和薪水
select * from tsm_employee where
commision >salary*0.6
--5、根据部门名称查询出该部门下所有项目经理和软件开发工程师的详细资料
select * from tsm_employee where dept_no=
(select dept_no from tsm_department where dept_name='软件开发87部')
and position in ('项目经理','软件开发工程师')
--6、根据部门名称查询该部门下所有项目经理、软件开发工程师以及薪金大于等于20000部门经理的的详细资料
select * from tsm_employee where dept_no=
(select dept_no from tsm_department where dept_name='软件开发87部')
and
(position in ('项目经理','软件开发工程师')
or (salary>=20000 and position='部门经理'))
--7、查询出佣金>0的雇员的所有职位
select distinct position from tsm_employee where commision>0
--8、查询出不收取佣金或收取的佣金低于100的雇员
select * from tsm_employee where commision is null or commision <100
--13、查询出不带有"军"的雇员姓名
select name from tsm_employee where name not like '%军%'
--15、查询所有雇员编码加上姓名作为一个列显示出来,并给出一个别名。
select emp_no||name bie from tsm_employee
--17、查询出雇员的详细资料,按姓名排降序
select * from tsm_employee order by name
--18、查询出雇员姓名,根据其服务年限,将最老的雇员排在最前面。
select * from tsm_employee order by create_date;
--19、查询出所有雇员的姓名、职位和薪金,按职位排降序,按薪金排升序
select name,position,salary from tsm_employee order by position desc,salary
--20、对于每个雇员,查询出其加入公司的天数
select month_between(sysdate,create_date)*30 from tsm_employee
--21、查询出姓名字段的任何位置包含"王"的所有雇员的姓名
select name from tsm_employee where name like '%王%'
--1、查询出至少有一个雇员的所有部门
select * from scott.dept where deptno in (select deptno from scott.emp);
--2、查询出薪金比输入的一个雇员7934多的所有雇员
select * from scott.emp where sal >
(select sal from scott.emp where empno=7934)
--3、
输入一个部门名称查询该部门中
所有雇员的姓名及其直接上级的姓名
select empno,ename,
mgr,(select ename from scott.emp where e.mgr=empno) mgrname
from scott.emp e where deptno=
(select deptno from scott.dept where dname='ACCOUNTING')--子查询完成的
select e.empno,e.ename,
e.mgr,e2.ename
from scott.emp e
left join scott.emp e2 on e.mgr=e2.empno
where e.deptno=
(select deptno from scott.dept where dname='ACCOUNTING')--使用连接查询
--4、查询出入职日期早于其直接上级的所有雇员
select e.empno,e.ename,e.hiredate,e.mgr,e2.ename,e2.hiredate from scott.emp e
left join scott.emp e2 on e.mgr=e2.empno
where e.hiredate < e2.hiredate
--5、查询出每个部门名称和部门中雇员人数(部门中没有雇员也要显示 人数为0),
select deptno,dname,
(select count(*) from scott.emp e where e.deptno=d.deptno) count
from scott.dept d
--6、查询出所有软件开发工程师的姓名及其部门名称
select empno,ename,
deptno,
(select dname from scott.dept d where d.deptno=e.deptno) dname
from scott.emp e where job='SALESMAN'
select empno,ename,
e.deptno,d.dname
from scott.emp e
inner join scott.dept d
on d.deptno=e.deptno
where job='SALESMAN'
--7、
查询出各种职位的最低薪金,
排除最低薪金大于15000的记录
select job,min(sal) from scott.emp group by job having min(sal)>1999
--8、查询出部门名称为"SALES"的雇员的姓名
select * from scott.emp where deptno=
(select deptno from scott.dept where dname='SALES')
--9、查询出薪金高于公司平均水平的所有雇员
select * from scott.emp where sal>
(select avg(sal) from scott.emp)
--10、查询出与某一位雇员SMITH从事相同职位的所有雇员
select * from scott.emp where job=
(select job from scott.emp where ename='SMITH')
--11、查询出各种职位的最低工资
select job,min(sal) from scott.emp group by job
--12、查询出各个部门的项目经理的最低薪金
--13、查询出按年薪排序的所有雇员的年薪
..select * from scott.emp order by sal*12 desc
--14、查询出薪金水平处于第四名的所有雇员
(select ename from scott.emp where rownum<5 )
minus
(select ename from scott.emp where rownum<4 )
select * from (select ename,sal,row_number() over
(order by sal desc) rn from scott.emp) where rn=4;
--15、查询出所有雇员的姓名的前二个字符
select substr(ename,1,2) from scott.emp
--16、查询出所有雇员的姓名以及满10年服务年限的日期
select ename ,empno ,hiredate, add_months(hiredate,120) from scott.emp
--17、查询出是每年2月来的所有雇员
select ename ,empno ,hiredate from scott.emp where
extract(month from hiredate)=2
--18、以年、月和日分别折算显示所有雇员的服务年限
(共几年 ;共几个月;共几天分三个字段显示。保留到小数点后2位)
..select hiredate,
round(months_between(hiredate,sysdate)/12,2) year,
round(months_between(hiredate,sysdate),2) month,
round(months_between(hiredate,sysdate)*30,2) day
from scott.emp
--19、以年、月和日显示所有雇员的服务年限
(到公司'几年几个月几天'由一个字段显示。以1个月30天计算,不考虑闰年)
..