How Can I Get The Sixth Maximum Salary From The EMP Table? In SQL Server.
Can't find what you're looking for?
Ask a Question, Get an Answer ASAP
In the given examples suppose table name is emp.
select max(sal) from emp e1 where (select count(sal) from emp e2 where e2.sal>=e1.sal)=6);
Or you can use the following query.
select distinct (a.sal) from emp A where &N=(select count(distinct b.sal)) from emp B where a.sal<=b.sal);
After running this query it will ask value for N here you can give 6 as you want to get the sixth maximum salary.
answered 2 years ago
Ask questions on any topic, get great answers from real people for FREE. Blurtit has hundreds of thousand of members so your sure to get the answer your looking for.