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 the class forname () does?
Explain activity monitors
You have to store user responses of ‘yes’ and ‘no’ what kind of data type is best suited for this task?
How to make a column nullable?
how many type of indexing in database?
What is a transaction and why is it important?
How are the unique and primary key constraints different?
What is the recovery model?
How to disable stored procedure sql server?
Why use “nolock” in sql server?
What does REVERT do in SQL Server 2005?
How to generate create procedure script on an existing stored procedure?
Explain what is dbcc?
Explain what is “asynchronous” communication in sql server service broker?
Can we write trigger for view?