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

How is use pl and sql?

556


What is the primary key?

538


Is sql between inclusive?

590


What is trigger and types?

565


What is varray in pl sql?

566






What is the difference between having and a where in sql?

572


Is a foreign key always unique?

534


What are keys in sql?

551


How many types of cursors are available in pl/sql?

586


How many functions are there in sql?

542


Which is faster truncate or drop?

562


Is t sql a programming language?

539


Explain the significance of the & and && operators in pl sql.

573


what is row? : Sql dba

712


What is mutating error?

511