Monday, July 13, 2009

Find nth Largest & Smallest value

Largest Value

SELECT a.StoreId FROM Stores a WHERE (n-1) = (select count(*) from Stores b where b.StoreId > a.StoreId)


Smallest Value

SELECT a.StoreId FROM Stores a WHERE (n-1) = (select count(*) from Stores b where b.StoreId < a.StoreId)

No comments:

Post a Comment