How to find maximum avg

前端 未结 15 2169
长情又很酷
长情又很酷 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:02
    select Dep_name
    from 
    (
      select Dep_name , avg(Salary) as avgsal 
      from salary
      group by Dep_name
    ) sal1
    where avgsal=(select  max(avgsal) 
                  from (select Dep_name , avg(salary) as avgsal 
                        from salary group by Dep_name) sal2)
    
    0 讨论(0)
  • 2020-12-15 20:07

    This worked out for me.

    from (select avg(salary) AS avg_salary
           from employees
          group by Name) AS T;
    
    0 讨论(0)
  • 2020-12-15 20:08

    using WITH clause it can be done as

    with averagesal as (
    select dept_id d_id, avg(sal) avgsal from emp_details group by dept_id)
    select * from averagesal where avgsal = (select max(avgsal) from averagesal);
    
    0 讨论(0)
  • 2020-12-15 20:08

    You should try the following approach:

    select avg(salary) as max_avg_salary from Salaries group by emp_no order by avg(salary) desc limit 1;
    
    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2020-12-15 20:17
    select * from (select avg(sal) over (partition by deptno ) avrg,deptno from emp
    order by avrg desc) where rownum<2;
    

    Try the above one.

    0 讨论(0)
提交回复
热议问题