Oracle-03

来源:互联网 发布:数据库百科 编辑:程序博客网 时间:2024/06/09 18:53

1./*求出某个员工的上级,并要求这些主管的薪水高于3000*/

这个需要左外连接 oracle中的外连接简写就是(+)

SQL> select distinct m.ename from emp e,emp m where e.mgr=m.empno(+) and m.sal>3000;

不用简写的写法:select distinct m.ename from emp e left join emp m on e.mgr=m.empno and m.sal>3000;

2./*求部门名称带字符‘S’的部门,员工,工资合计,部门人数*/

SQL> select d.dname,e.ename,m.sum,m.count from emp e,dept d,(select deptno,sum(sal) sum,count(*) count from emp group by deptno) m where e.deptno=m.deptno and d.deptno=m.deptno and d.dname like '%S%';

这个比较多一点

3.给任职日期超过十年的人加薪10%

update emp set sal=sal*1.1 where months_between(sysdate,hiredate)>120;

4./*.按照员工的部门号升序排列,同部门的再按员工工资降序排列;*/

SQL> select * from emp order by deptno,sal desc;

5./*查出哪个部门的工资是最低的。*/