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
Which tcp/ip port does the sql server run on? How can it be changed?
How we can compare two database data?
What is ssl in sql server?
When we should use and scope of @@identity?
What are “lost updates”?
What are 3 ways to get a count of the number of records in a table?
What is BLOCK statements in SQL?
What is reportserver and reportservertempdb ?
How do I know if localdb is running?
How to convert a unicode strings to non-unicode strings?
You have several tables, and they are joined together for querying. The tables contain both clustered indexes and non clustered indexes to optimize performance, how should you distribute the tables and their indexes onto different file groups?
What do you need to connect php to sql server?
How to turn on the mssql api module in php?
What are subquery and its properties?
What is the standby server?