select * from scott.emp e where e.sal > (select avg(sal) from scott.emp where deptno=e.deptno);

解决方案 »

  1.   

    写成这样,你应该明白了吧?select m.* from scott.emp m 
    (select deptno , avg(sal) sal_avg from scott.emp group by deptno) n
    where m.deptno = n.deptno and m.sal > n.sal_avg
      

  2.   

    我想知道select avg(sal) from scott.emp where deptno=e.deptno是不是将不同的各个部门的平均工资都返回?select * from scott.emp e where e.sal > (select avg(sal) from scott.emp where deptno=e.deptno);
    还有整个语句的执行有没有什么先后顺序的?
      

  3.   

    我想知道select avg(sal) from scott.emp where deptno=e.deptno是不是将不同的各个部门的平均工资都返回?改成select avg(sal) from scott.emp group by deptno
      

  4.   

    select avg(sal),deptno from scott.emp group by deptno