Connect scott/tiger@orcl;
select * from emp
select * from salgrade
select * from dept
1、查询Scott的工资等级
select grade from salgrade where losal<=(select sal from emp where ename='SCOTT') and hisal >=(select sal from emp where ename='SCOTT')
select grade from emp inner join salgrade on sal>=losal and sal<=hisal where ename='SCOTT'
2、查询各部门的平均工资
select deptno,avg(sal) from emp group by deptno
3、查询平均工资最高的部门名称
技巧(只取第一条记录):
select * from (select ename from emp order by ename) t1 where rownum <=1;
select dname from dept where deptno=(select * from (select deptno from emp group by deptno order by avg(sal) desc) t1 where rownum <=1);
4、查询管理Scott的直接管理者
select ename from emp where empno=(select mgr from emp where ename='SCOTT')
select t2.ename from emp t1 inner join emp t2 on t1.mgr=t2.empno where t1.ename='SCOTT'
5、查询薪金比“SMITH”多的所有员工(利用自连接表达)
select e2.ename from emp e1 inner join emp e2 on e1.sal<e2.sal where e1.ename='SMITH'
select ename from emp where sal>(select sal from emp where ename='SMITH')
[此贴子已经被作者于2010-12-11 20:29:00编辑过]