select top 3 sal from each dept?

Answer Posted / divakarreddy

SQL> select *from (select ename,sal,deptno,rank()
2 over(partition by deptno order by sal desc)topsal
3 from emp)
4 where topsal<=3
5 order by deptno,sal desc;

ENAME SAL DEPTNO TOPSAL
---------- ---------- ---------- ----------
KING 5000 10 1
MILLER 3000 10 2
CLARK 2450 10 3
SCOTT 3000 20 1
JONES 2975 20 2
ADAMS 1100 20 3
BLAKE 2850 30 1
ALLEN 1600 30 2
TURNER 1500 30 3

9 rows selected.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are secondary keys?

655


How do I order columns in sql?

619


what does it mean to have quoted_identifier on? What are the implications of having it off? : Sql dba

627


Can we insert in sql function?

654


Why is partition used in sql?

668






What is the difference between pl and sql?

628


what are date and time intervals? : Sql dba

645


How do you write an index?

620


What is the benefit of foreign key?

621


What are some predefined exceptions in pl/sql?

648


what are enums used for in mysql? : Sql dba

713


Can 2 queries be executed simultaneously in a distributed database system?

747


How do I create a sql database?

620


Can we use rowid as primary key?

638


What are different types of indexes?

601