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
Are pl sql variables case sensitive?
Why are indexes and views important to an organization?
which tcp/ip port does sql server run on? : Sql dba
What is partition in sql query?
what is log shipping? : Sql dba
How to use boolean type in select statement?
What can you do with pl sql?
How do I view stored procedures?
what is dbms? : Sql dba
what are different types of keys in sql?
How much does sql cost?
explain advantages of innodb over myisam. : Sql dba
What is sql*loader and what is it used for?
What is a primary key sql?
How do I view a procedure in sql?