Pages

Saturday, September 21, 2013

SQL SERVER – Query to Retrieve the Nth Maximum Value | Journey to SQL Authority with Pinal Dave

Replace Employee with your table name, and Salary with your column name. Where N is the level of Salary to be determined. SELECT * FROM Employee E1 WHERE (N-1) = ( SELECT COUNT(DISTINCT(E2.Salary)) FROM Employee E2 WHERE E2.Salary > E1.Salary) In the above example, the inner query uses a value of the outer query in its filter… Continue Reading...

Source: SQL SERVER – Query to Retrieve the Nth Maximum Value | Journey to SQL Authority with Pinal Dave

No comments:

Post a Comment