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

Is ms sql traffic encrypted?

681


How do I start pl sql?

668


What is the use of count (*) in sql?

751


What are the features of pl sql?

766


What is materialized view in sql?

650






How do you truncate?

660


How long it takes to learn pl sql?

720


What is rownum?

708


How many sql are there?

733


How would you reference column values before and after you have inserted and deleted triggers?

815


Does sap use sql?

717


Which is faster view or stored procedure?

688


what is normalization? : Sql dba

737


What is a database trigger?

789


What is the difference between alter trigger and drop trigger statements?

795