日期:2014-05-17 浏览次数:20793 次
SELECT * FROM emp t WHERE t.sal > (SELECT AVG(b.sal) FROM emp b WHERE t.deptno = b.deptno);
------解决方案--------------------
SELECT * FROM emp t,(SELECT deptno, AVG(sal) sal FROM emp group by deptno) b WHERE t.sal >b.sal and t.deptno=b.deptno ;
------解决方案--------------------
楼上的正解
不过也可以这么写
select * from scott.emp t1
where t1.sal > (select sal from
(select deptno,avg(sal) sal from scott.emp group by deptno) t2 where t1.deptno = t2.deptno);
------解决方案--------------------
SELECT t.* FROM emp t,(SELECT deptno, AVG(sal) sal FROM emp group by deptno) b WHERE t.sal >b.sal and t.deptno=b.deptno
------解决方案--------------------