这是oracle数据库里的两张表 emp和sal 字段分别有:
EMPNO        雇员编号
ENAME          雇员名字
JOB                工作
MGR              上司
HIREDATE      入职日期
SAL                工资
COMM          津贴
DEPTNO        部门编号
第二张表字段有
GRADE      工资等级
LOSAL        某一等级的最底工资
HISAL          某一等级的最高工资问题:要求求出每个部门的平均工资是何种等级。谢谢

解决方案 »

  1.   

    select t.*,grade from (select deptno,avg(sal) asal from emp group by deptno) t,
    sal
    where t.asal between losal and hisal;
      

  2.   

    select s.grade ,a.deptno
    from salgrade s,
    (select e.deptno,avg(e.sal) as sal
    from emp e,salgrade s
    group by e.deptno) a
    where a.sal between losal and hisal
      

  3.   

    select a.DEPTNO,sal.GRADE
    from (
        select DEPTNO,avg(SAL) as avg_sal
        from emp
        group by DEPTNO) a , sal
    where a.avg_sal between sal.LOSAL and sal.HISAL