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
How do we synchronize On-Premise SQL server with SQL Azure?
Can we add an identity column to decimal datatype?
Can we insert data into view sql server?
Can you explain about buffer cash and log cache in sql server?
How connect excel to sql server?
How to assign new column names in a view?
What is indexing explain it with an example?
What are orphan records?
What are group functions in query statements in ms sql server?
How do I setup a sql server database?
Is sql server 2016 free?
What is the difference between value type and reference type?
How do I open a .db file?
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 is side by side migration in sql server?