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
what are the maximum number of rows that can be constructed by inserting rows directly in value list? : Transact sql
which command using query analyzer will give you the version of sql server and operating system? : Sql dba
What does seeding a database mean?
Can we have two clustered index on a table?
What are the events on which a database trigger can be based?
what is normalization? : Sql dba
Can a table contain multiple primary key’s?
what is 'mysqlimport'? : Sql dba
Is pl sql and postgresql same?
Which table is left in left join?
What does count (*) do in sql?
What is out parameter used for eventhough return statement can also be used in pl/sql?
How do you use a while loop in pl sql?
What programs use sql?
Define tables and fields in a database