Topic: SQL*Plus and PL/SQL >> pla help me.
|
Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property.
You may review the entire Oracle Certification Program Candidate Agreement online Here.
|
|
|
|
| Garlapati |
Posted: Feb 29, 2008 03:37:53 AM |
Total Post: 30
Joined: Apr, 2007
|
i want to diaply the top6 salaries in each department
pla help me.
thanq advance
|
|
|
pammi |
| Posted: Feb 29, 2008 04:20:55 AM | |
|
Total Post: 21
Joined: Feb, 2008
|
I have the solution in pl/sql. Just go thru it.
declare
cursor c1 is select deptno from dept;
c2 c1%rowtype;
cursor c3(dno number) is
select rownum,sal from(select distinct sal ,deptno from emp where sal is not null order by sal desc ) where rownum<=6
and deptno=dno;
c4 c3%rowtype;
begin
open c1;
loop
fetch c1 into c2;
exit when c1%notfound;
dbms_output.put_line(c2.deptno);
for c4 in c3(c2.deptno) loop
dbms_output.put_line( c4.rownum|| ' ' ||c4.sal);
end loop;
end loop;
close c1;
end;
/
|
|
|
|
|
Murtuja |
| Posted: Feb 29, 2008 04:27:27 AM | |
|
Total Post: 857
Joined: Jan, 2006
|
Hi ,
SELECT * FROM (
SELECT deptno, ename, sal,
DENSE_RANK()
OVER (
PARTITION BY deptno ORDER BY sal desc
) TopN FROM emp
)
WHERE TopN <= 6
ORDER BY deptno, sal DESC
|
|
|
|
|
| Time Zone: EDT |
Send this thread to your friend |
|
|
|
|
Forum Rules & Description
Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user
|
| |
Get FREE Magazines
|
Top 10 Forum User
|
| Murtuja Khokhar | 857 |
| Mohammed Taj | 746 |
| positive fanatic | 483 |
| Jayanta Sur | 479 |
| Vigyan Kaushik | 387 |
| Vinoth Kumar | 379 |
| Gopu Gopi | 350 |
| Gitesh Trivedi | 322 |
| neeraj sharma | 258 |
| Ramesh Jois | 246 |
|
|