select top 3 sal from each dept?

Answer Posted / venkateswara thiruvedhula

SELECT empno,
deptno,
sal,
RANK() OVER (PARTITION BY deptno ORDER BY sal
desc) "rank"
FROM emp;

EMPNO DEPTNO SAL rank
---------- ---------- ---------- ----------
7934 10 5000 1
7782 10 3000 2
7839 10 2000 3
7369 20 2950 1
7876 20 1700 2
7566 20 1100 3
7788 20 900 4
7902 20 900 4

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we alter stored procedure?

557


How do I truncate a sql log file?

548


write an sql query to get third maximum salary of an employee from a table named employee_table. : Sql dba

553


How can the performance of a trigger be improved?

602


What is the difference between unique and primary key constraints?

594






what is a control file ? : Sql dba

590


Which is better join or inner query?

528


Does inner join return duplicate rows?

530


What is mutating error?

514


Explain how you can copy a file to file content and file to pl/sql table in advance pl/sql?

558


Can we call dml statement in function?

553


What are the constraints available in sql?

592


What is the difference between sql and t sql?

544


Why do we use cursors?

522


What is difference between hql and sql?

518