Assume that there is a 'Employee' table with salary as one of the columns.
I want to get the 'Top N'th maximum salary alone from the table.
How this can be fetched easily?
Assume that there is a 'Employee' table with salary as one of the columns.
I want to get the 'Top N'th maximum salary alone from the table.
How this can be fetched easily?
SELECT TOP N employee.name, employee.salary
FROM employee
ORDER BY employee.salary DESC
?
SELECT TOP 1 Salary FROM
(SELECT TOP(N) Salary FROM Employee
ORDER BY Salary DESC) E
SELECT TOP 1 employee.name, employee.salary from (
SELECT TOP N employee.name, employee.salary
FROM employee
ORDER BY employee.salary DESC )
This gives the Nth from the top.
WITH (
SELECT e.*, ROW_NUMBER() OVER (ORDER BY employee.salary DESC) AS rn
FROM employee
) AS q
SELECT *
FROM q
WHERE rn = @n