adspace


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 aggregate and scalar functions? : Sql dba

1127


what is dbms? : Sql dba

1061


What is the best sql course?

1050


what is collation? : Sql dba

1229


how many tables will create when we create table, what are they? : Sql dba

1144


what are the advantages of sql ? : Sql dba

1141


Is primary key clustered index?

1018


What is the current version of postgresql?

1177


Is primary key always clustered index?

1094


How do I remove duplicates in two columns?

1185


how to start mysql server? : Sql dba

1266


Can delete statement be rollbacked?

1053


Does group by remove duplicates?

1112


What is your daily office routine?

2345


Do we need to rebuild index after truncate?

1137