select select max(avg(sal)) from emp group by deptno中怎么样可以同时把deptno 号显示出来呢?
select deptno,max(avg(sal)) from emp group by deptno
select deptno,avg(sal)
from emp group by deptno
having avg(sal) =
(select max(avg(sal)) from emp group by deptno);
上面的sql语句漏了desc
select *
from (select deptno, avg(sal) avgsal
from emp
group by deptno
order by avgsal desc)
where rownum=1;
一楼那个写法是错的,max似乎不能跟部门号同时使用,我想了个比较绕的办法把最大部门平均工资跟部门号一起显示出来,欢迎有同学贡献更好的办法
select *
from (select deptno, avg(sal) avgsal
from emp
group by deptno
order by avgsal)
where rownum=1;