To fetch the nth highest or lowest value in sql.
For example To fetch the 4th highest value , replace 1 by 4 in the below query.
select * from test e where 1=(select count(distinct sal) from test where e.sal>=sal);
To fetch the 4th lowest value , replace 1 by 4 and replace the '>' with '<' in the above query.
No comments:
Post a Comment