Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Write a query to display the top 5 salaries in each department from employees table in HR schema

user-image
Question added by Sameh Mohamed Aly Sewilam , Oracle Technical Team Leader , National Technology
Date Posted: 2014/07/14
Deepali singh parmar
by Deepali singh parmar , TEST ANALYST , NETLINK SOFTWARE

SELECT*FROM(SELECT*FROM emp ORDERBY Salary desc)WHERE rownum <=5ORDERBY Salary;

Suhail Mohammed A
by Suhail Mohammed A , Oracle Consultant , Morpho

select sal from (

select sal, dense_rank() over(order by sal desc) rnk from emp)

where rnk<5

Ahmed Hossam El-Dien El-Hansy
by Ahmed Hossam El-Dien El-Hansy , Senior Software Developer , Thiqah business service

select * from scott.employee X where salary in (select top 5 salary from scott.employee where dept = X.dept order by salary desc) order by dept, salary desc

SUMALATHA DONTHU
by SUMALATHA DONTHU , Trainee

SELECT EMPNO,ENAME.SAL

FROM

(

SELECT EMPNO,ENAME,SAL,ROW_NUMBER()OVER(PARTITION BY DEPTNO ORDER BY SAL) AS RNK FROM EMP

)A

WHERE A.RNK<=5

Mohammed Mahir Ameen
by Mohammed Mahir Ameen , IT Consultant , Kuwait Airways

Select * From (SELECT A.*,

(SELECT COUNT(DISTINCT(B.salary))

FROM Employee B

WHERE B.salary >= A.salary and A.departmentID=B.departmentID) as Rank FROM  Employee A) Emp

Where Emp.Rank <=5

imtiaz ali
by imtiaz ali , ORACLE DBA , Peshawar Electric Supply Company Head Quarter

select * from (select * from employees order by salary desc) where rownum<= 5 ORDER BY salary;

Manoj Balakrishnan
by Manoj Balakrishnan , QA Engineer

SELECT*FROM(SELECT ename, sal, DENSE_RANK()OVER(ORDERBY SAL DESC) EMPRANK FROM emp )WHERE emprank <=5

Mohamed ali Abdul Majith
by Mohamed ali Abdul Majith , Web Developer , Solaripe General Trading LLC

 

SELECT TOP 5 b.DepartName,a.Salary FROM Employee a

JOIN 

Department b ON a.DepartId=b.DepartId

group by b.DepartName ORDER BY a.Salary DESC

ranam maktabi
by ranam maktabi , manager of programming and dba oracle , electrcity Aleppo

SELECT DISTINCT DEPARTMENT_ID, salary,row_number() OVER (PARTITION BY DEPARTMENT_ID ORDER BY salary DESC) row_no  FROM hr.employees 

Kartiki Rathod
by Kartiki Rathod , Junior Programmer Analyst , Rheal Software Technology Solutions LLP

 

;with temp as 

(

select dept, salary ,ROW_NUMBER() over (partition by dept order by salary desc) row_no from Employee

)

 

select dept,salary from temp where row_no <=5

Sameh Mohamed Aly Sewilam
by Sameh Mohamed Aly Sewilam , Oracle Technical Team Leader , National Technology

SELECT DISTINCT department_no, salary           FROM (SELECT department_no, salary,                        DENSE_RANK () OVER (PARTITION BY department_no ORDER BY salary DESC NULLS LAST) rn                                                                                            FROM employees)          WHERE rn <=5       ORDER BY department_no, salary DESC;

More Questions Like This