FIND Nth Maximum value
SELECT id, amount FROM(SELECT id, amount, Row_Number() OVER(ORDER BY amount DESC) AS highest FROM @tmp ) as x WHERE highest = 3 -- FIND Nth Minimum value
SELECT id, amount FROM(SELECT id, amount, Row_Number() OVER(ORDER BY amount ASC) AS lowest FROM @tmp ) as x WHERE lowest = 3
No comments:
Post a Comment