Tuesday, September 15, 2009

Find Nth Highest Salary

Select *
From Employee_Salary

OUTPUT
Emp_Id Emp_Name Salary
1 Mahmad 13500
2 Bharat 9000
3 Tausif 8000
4 Amol 8500
5 Rajkumar 24500
6 Pankaj 28200
7 Sameer 18000
8 Sunil 16800

Below query will give third highest salary employee

Select *
From (
select Emp_Id,Emp_Name,Salary,
Dense_Rank() Over (Order By Salary Desc) as Dense_Rank
from Employee_Salary
) as A
Where A.Dense_Rank = 3

OUTPUT
Emp_Id Emp_Name Salary Dense_Rank
7 Sameer 18000 3

No comments: