i need department wise top 2 employees salary.which logic
i will use

Answer Posted / nag

select distinct(sal), deptno from
(select * from emp a where 1 = (select count(distinct sal)+1
from emp b where b.sal > a.sal and b.deptno = a.deptno) and
deptno is not null
union
select * from emp a where 2 = (select count(distinct sal)+1
from emp b where b.sal > a.sal and b.deptno = a.deptno)and
deptno is not null)
order by deptno,sal

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is scope and visibility in PL/SQL?

766


Is primary key is clustered index?

714


what is the difference between union and union all? : Sql dba

718


Why do we need view in sql?

724


What is pl sql commands?

728






What does the file extension accdb stand for?

701


Is it mandatory for the primary key to be given a value when a new record is inserted?

925


Explain the difference between 'between' & 'and' operators in sql

715


How to get help at the sql prompt?

824


What is anonymous block in sql?

816


What is the difference between Union and Union all. Which is faster.

1061


What is hibernate and its relation to sql?

782


Why do we go for stored procedures?

724


What is rowid in sql?

670


how to check myisam tables for errors? : Sql dba

878