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

Answer Posted / neo

select t1.empno, deptno, sal from emp t1 where t1.sal =
(select max(t2.sal) from emp t2 where t1.deptno = t2.deptno
group by deptno)
union
select t1.empno, deptno, sal from emp t1 where t1.sal =
(select max(t2.sal) from emp t2
where t2.sal < (select max(t3.sal) from emp t3 where
t3.deptno = t2.deptno and t1.deptno = t2.deptno )
group by deptno)
order by deptno, sal desc;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are the maximum number of rows that can be constructed by inserting rows directly in value list? : Transact sql

498


which command using query analyzer will give you the version of sql server and operating system? : Sql dba

522


What does seeding a database mean?

525


Can we have two clustered index on a table?

560


What are the events on which a database trigger can be based?

592






what is normalization? : Sql dba

559


Can a table contain multiple primary key’s?

622


what is 'mysqlimport'? : Sql dba

570


Is pl sql and postgresql same?

567


Which table is left in left join?

521


What does count (*) do in sql?

520


What is out parameter used for eventhough return statement can also be used in pl/sql?

582


How do you use a while loop in pl sql?

534


What programs use sql?

523


Define tables and fields in a database

644