Sunday, August 14, 2011

Getting Nth highest salary (will work for all databases)

SELECT * FROM employee e1 WHERE (n-1)=(SELECT COUNT(DISTINCT salary) FROM employee  e2 WHERE e2.salary>e1.salary)

*n - Nth highest salary

No comments:

Post a Comment