Find Nth max salary Joining two different tables.














  1. SELECT DISTINCT D.DeptName
  2. ,E.Salary AS [nth Highest Salary]
  3. FROM DEPT D
  4. LEFT OUTER JOIN Employee E ON D.ID = E.DeptID
  5. WHERE n = (
  6. SELECT COUNT(DISTINCT Salary)
  7. FROM Employee Aux
  8. WHERE Aux.Salary >= E.Salary
  9. AND Aux.DeptID = E.DeptID
  10. )
  11. ORDER BY D.DeptName;
  12. GO
  13.  
Find Nth max salary Joining two different tables. Find   Nth  max   salary  Joining   two different  tables. Reviewed by Mukesh Jha on 5:57 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.