Get Top 3rd salary using MS SQL server
You can get any number of Top salary by using below query
WITH CTE AS
(
SELECT EmpID, EmpName, EmpSalary,
RN = ROW_NUMBER() OVER (ORDER BY EmpSalary DESC)
FROM dbo.Salary
)
SELECT EmpID, EmpName, EmpSalary
FROM CTE
WHERE RN = @NthRow
If somebody ask for Top 3rd salary, then i'll replace 3 to @NthRow then i'll execute query. and then i'll get top 3rd salary.
Comments
Post a Comment