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

Explain what is an index?

606


Is sql a programming?

554


what is a field in a database ? : Sql dba

555


What is the current version of sql?

548


Why we use joins in sql?

548






i have 2 table table one 4 columns respective values a1 7,a2 6,a3 8 ,a4 12 & table two 4 colums respective values a1 7,a2 6,a3 8,a4 15.if table one & table two 3 colums same then 4th column values 1)Qes diff >5 then print 5 * diff value 2)Que diff <5 print 5

3218


List and explain the different types of join clauses supported in ansi-standard sql?

831


How do you break a loop in pl sql?

533


how would you write a query to select all teams that won either 2, 4, 6 or 8 games? : Sql dba

788


Is pl sql and postgresql same?

584


what are all the different normalizations? : Sql dba

515


How run sql*plus commands that are stored in a local file?

528


how to run 'mysql' commands from a batch file? : Sql dba

618


What is pessimistic concurrency control? : Transact sql

595


How long does it take to learn pl sql?

618