what is syntex second or third highest salary.
thanks & Regards
Dhirendra sinha
Answer Posted / satish
select max(sal) from emp e1 where 1< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)
To make it generic if u want N'th highest salary;
select max(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)
And to get the N'th min sal :
select min(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal >= e2.sal)
Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are views in ms sql server?
How many types of the database links?
What is compound operators?
What methods do you follow to protect from sql injection attack?
What is pivot and unpivot?
What is scd (slowly changing dimension)? : sql server analysis services, ssas
Difference between DELETE and TRUNCATE?
What is the main purpose of having conversation group?
Write the syntax for stuff function in an sql server?
How to convert a unicode strings to non-unicode strings?
what method you can use to reduce the overhead of Reporting Services data sources?
Why do we use non clustered index?
What is the difference between index seek vs. Index scan?
What is difference between aggregate and analytic function?
What is clustered index