how will I find the first 5 highest salaried employees in
each dept in oracle.
Answer Posted / sreeharibabu
select * from (select emp.*,row_number() over(partition by deptno order by sal desc) rnk from emp) where rnk <=5 ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO RNK
1 7839 X PRESIDENT 11/17/1981 5000.00 10 1
2 7782 X MANAGER 7839 6/9/1981 2450.00 10 2
3 7934 X CLERK 7782 1/23/1982 1300.00 10 3
4 700 X b 1234 9/9/2016 10:48:53 PM 1000.00 0.00 10 4
5 7369 X CLERK 7902 12/17/1980 8800.00 20 1
6 7788 X ANALYST 7566 4/19/1987 3000.00 20 2
7 7902 X ANALYST 7566 12/3/1981 3000.00 20 3
8 7566 X MANAGER 7839 4/2/1981 2975.00 20 4
9 7876 X CLERK 7788 5/23/1987 1100.00 20 5
10 7698 X MANAGER 7839 5/1/1981 2850.00 30 1
11 7499 X SALESMAN 7698 2/20/1981 1600.00 300.00 30 2
12 7844 X SALESMAN 7698 9/8/1981 1500.00 0.00 30 3
13 7521 X SALESMAN 7698 2/22/1981 1250.00 500.00 30 4
14 7654 X SALESMAN 7698 9/28/1981 1250.00 1400.00 30 5
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are the different pseudo commands? Explain in general?
What is connection pooling in oracle?
In what script is snap$ created? In what script is the scott/tiger schema created?
What is query image?
How do I start tns listener?
Point the difference between translate and replace?
How to apply filtering criteria at group level in oracle?
Provide an example of a shell script which logs into SQLPLUS as SYS, determines the current date, changes the date format to include minutes & seconds, issues a drop table command, displays the date again, and finally exits.
How to use "in" parameter properly?
How to initialize variables with default values?
normally database take to refresh time 2 hours. but client asked iwant to refresh with in 5 min that same database. do you have any option in BO and Oracle? explain me briefly...kavi
Is there any way to find out when one specific table/view/M-view is used last time. i.e. when one specific object is used in any SELECT statement.
Can we write insert statement in function in oracle?
Explain an exception?
what is the scenario where you take the database to NoArchivelog mode?