5 pts.
 Find the employees who earn a salary greater than the average salary for their departments using a SQL query
Find the employees who earn a salary greater than the average salary for their departments using a SQL query

Software/Hardware used:
ASKED: July 18, 2008  12:07 PM
UPDATED: April 13, 2011  6:24 AM

Answer Wiki:
The easiest method is to use a subquery as a JOIN in your <a href="http://itknowledgeexchange.techtarget.com/sql-server/back-to-basics-the-select-statement/">SELECT</a> Statement. Something like this. <pre>SELECT Employee.* FROM Employee JOIN (SELECT DepartmentId, AVG(Salary) Salary FROM Employee GROUP By DepartmentId) SalaryInfo ON Employee.DepartmentId = SalaryInfo.DepartmentId AND Employee.Salary > SalaryInfo.Salary</pre>
Last Wiki Answer Submitted:  July 18, 2008  5:41 pm  by  Denny Cherry   64,520 pts.
All Answer Wiki Contributors:  Denny Cherry   64,520 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,520 pts.