How to find maximum avg

前端 未结 15 2208
长情又很酷
长情又很酷 2020-12-15 19:17

I am trying to display the maximum average salary; however, I can\'t seem to get it to work.

I can get a list of the average salaries to display with:



        
15条回答
  •  [愿得一人]
    2020-12-15 20:13

    select max(a.high)Avg_highest_salary,
           e.dept 
    from  (
        select avg(salary) high,dept from emp group by dept) a,
        emp e 
    where  a.dept = e.dept
    group by   e.dept
    order by   max(a.high) desc
    

    It will show the high Average highest salary first with dept

    If you don't want to show the Salary with Dept then you can use this

    select max(avg(salary)) max_avg_salary
    from emp
    group by dept;
    

提交回复
热议问题