Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Sameh Mohamed Aly Sewilam , Oracle Technical Team Leader , National Technology
Date de publication: 2014/07/14
Deepali singh parmar
par Deepali singh parmar , TEST ANALYST , NETLINK SOFTWARE

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

Suhail Mohammed A
par 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
par 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
par 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
par 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
par 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
par 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
par 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
par 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
par 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
par 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