Tuesday, August 27, 2013
Find nth Min/Max values in SQL Server
Finding Nth minimum salary:1.In SQL Server 2000/2005
SELECT salary FROM employees e1 WHERE (N = (SELECT COUNT(DISTINCT (e2.salary))
FROM employees e2 WHERE e2.salary <= e1.salary))
Finding Nth maximum salary:
1.In SQL Server 2000/2005
SELECT salary FROM employees e1 WHERE (N = (SELECT COUNT(DISTINCT (e2.salary))
FROM employees e2 WHERE e2.salary >= e1.salary))
Hope you find it useful.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment