Facebook Twitter Reddit LinkedIn

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: http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx
© 2007-2019 All rights reserved.   Part of the somuch.com group of trusted web sites.   PO Box 1542, Ormond Beach FL 32175