问答详情
源自:2-9 [Oracle] 分组函数的嵌套

关与分组函数嵌套问题

select select max(avg(sal)) from emp group by deptno中怎么样可以同时把deptno 号显示出来呢?


提问者:洪小仔 2015-09-22 21:11

个回答

  • 吴学究
    2015-12-18 10:43:24
    已采纳

     select deptno,max(avg(sal)) from emp group by deptno

  • creolive
    2018-02-19 17:16:22

    select deptno,avg(sal) 

    from emp group by deptno

    having avg(sal) =

    (select max(avg(sal)) from emp group by deptno);


  • 红袖侍读
    2016-10-31 02:28:50

    上面的sql语句漏了desc

    select *

    from (select deptno, avg(sal) avgsal

              from emp

              group by deptno

              order by avgsal desc)

    where rownum=1;

  • 红袖侍读
    2016-10-31 02:27:22

    一楼那个写法是错的,max似乎不能跟部门号同时使用,我想了个比较绕的办法把最大部门平均工资跟部门号一起显示出来,欢迎有同学贡献更好的办法

    select *

    from (select deptno, avg(sal) avgsal

              from emp

              group by deptno

              order by avgsal)

    where rownum=1;