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:
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)
This worked out for me.
from (select avg(salary) AS avg_salary
from employees
group by Name) AS T;
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);
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;
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;
select * from (select avg(sal) over (partition by deptno ) avrg,deptno from emp
order by avrg desc) where rownum<2;
Try the above one.