How to get N-th max value

declare @N int
set @N = 5
Select *
From Employee E1
Where (@N-1) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where E2.Salary > E1.Salary)

Source: https://weblogs.sqlteam.com/mladenp/2005/08/01/7421/
Viewed 16525 times