Skip to Main Content
  • Questions
  • SQL query to find employees earning more than department average

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Venkat.

Asked: October 13, 2016 - 7:07 am UTC

Last updated: October 13, 2016 - 10:03 am UTC

Version: oracle 11g

Viewed 1000+ times

You Asked

My question..
how to write query to display the employee who are getting more salary then the average salary to the department_number from department table.

thanks in advance...

and Chris said...

Hmmm, no create table, no sample data, no expected output!

It really, really, really helps us ensure we're giving you the correct answer if you provide these details!

So here's what I think you're looking for:
select employee_id, salary from (
  select e.*, avg(salary) over (partition by department_id) d_avg 
  from   hr.employees e
  where  department_id = 60
)
where  salary > d_avg;

EMPLOYEE_ID  SALARY  
103          9,000   
104          6,000 


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Analytics

Analytic SQL got you confused? Check out Connor McDonald's complete video course.