Related to Average
Related to Average
(OP)
HI All,
I Have a table like below,
I want to find the employees in each department who earn more than average salary in that department. How to write this query in SQL. Please help. I'm new to SQL Programming.
I tried the below query but it did not give the correct output.
Thank you.
I Have a table like below,
CODE -->
EmpID Name Salary Department
I want to find the employees in each department who earn more than average salary in that department. How to write this query in SQL. Please help. I'm new to SQL Programming.
I tried the below query but it did not give the correct output.

CODE -->
select * from Employee E1 where Salary > (select avg(salary) from Employee E2 where E2.Department = E1.Department )
Thank you.
RE: Related to Average
that[every] department.'Select Department, AVG(Salary) As AVG_Salary
From Employee Group By Department
And the second step would be to incorpoprate step one into:
Select E.EmpID, E.Name, E.Salary, A.AVG_Salary, E.Department From Employee E, (Select Department, AVG(Salary) As AVG_Salary From Employee Group By Department) A Where E.Department = A.Department And E.Salary > A.AVG_Salary
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson