I am working on a project where there is a requirement to get TOP 5 salaries excluding MAX salary. Suppose MAX salary is 67000, then I have to show top five salaries excluding 67000.
Getting top5 salary excluding max salary
177102-Mar-2015
Updated on 02-Mar-2015
Anonymous User
02-Mar-2015Hi,
SQL Server has OFFSET through which you can exclude first row, so you can just sort the records by salary in descending order and remove first row, it will give you what you want.
Here is the SQL Query that could help you:
select Salary from Employee ORDER BY salary DESC OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY
Anonymous User
02-Mar-2015You can use ranking to get top 5 salaries excluding the highest salary
Takeshi Okada
02-Mar-2015You can use below query to get your desired result
select Top 5 Salary from Employee where Salary < (select MAX(salary) from Employee) order by salary desc