Monday, November 7, 2016

To find Nth maximum salary

To find nth max salary using correlated query
SELECT * /*This is the outer query part */
FROM Employee Emp1
WHERE (N-1) = ( /* Subquery starts here */
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)
view raw maxSal.sql hosted with ❤ by GitHub

No comments:

Post a Comment