Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value
Suppose we hav a table name Employee and in this table we have a column name Salary----
so what would b the query for Find 2nd Highest Salary of Employee......
Select Top 1 Salary from ( select Top 2 Salary from Employee order by Salary desc) a order by Salary
You can change and use it for getting nth highest salary from Employee table as follows
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
so what would b the query for Find 2nd Highest Salary of Employee......
Select Top 1 Salary from ( select Top 2 Salary from Employee order by Salary desc) a order by Salary
You can change and use it for getting nth highest salary from Employee table as follows
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
Labels: Find Nth Highest Salary of Employee – Query to Retrieve the Nth Maximum value
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home