SQL练习题:
--练习004的所学内容
--1.查看工资高于2000的员工
select * from emp where sal >2000;
--2.查看不是“CLERK”职位的员工
select * from emp where job <> 'CLERK';
--3.查看工资在1000-2500之间的员工
select * from emp where sal >=1000 and sal <=2500;
--4.查看名字是以K结尾的员工
select * from emp where ename like '%K';
--5.查看20,30号部门的员工
select e.*
from emp e, dept d
where e.deptno = d.deptno
and d.deptno in ('20', '30');
--6.查看奖金为null的员工
select * from emp where comm is null;
--7.查看年薪高于2000的员工
select * from emp where sal*12>20000;
select * from emp where sal>20000/12;
--8.查看公司共有多少个职位
select count(deptno) from dept ;
--9.按部门号从小到大排列查看员工
select * from emp order by deptno;
--10.查看每个部门的最高,最低,平均工资,和工资总和
select deptno, max(sal), min(sal), avg(sal), sum(sal)
from emp
group by deptno;
--11.查看平均工资高于2000的部门的最低薪水
select deptno, min(sal) from emp group by deptno having avg(sal) > 2000;
--12.查看在NEW YORK工作的员工
select *
from emp e, dept d
where e.deptno = d.deptno
and d.loc = 'NEW YORK';
select *
from emp e
join dept d
on e.deptno = d.deptno
and d.loc = 'NEW YORK';
--13.查看所有员工以及所在部门信息,若该员工没有部门,则
--部门信息以null值显示
select * from emp e, dept d where e.deptno = d.deptno(+)
--14.查看ALLEN的上司是谁?
select e.ename, m.empno, m.ename
from emp e, emp m
where e.mgr = m.empno
and e.ename = 'ALLEN';