Jul 27, 2020 11:14 am
Hi ,
Can anyone help me with how to find 5 the highest salary in the employee table?
1 Reply
Jul 28, 2020 3:02 am
There are different ways to achieve this. However, I prefer a common table expression in order to capture the highest salaries from a table.
Let us say I want to capture top 5 employees from the employee table based on their salary. Using common table expression I can write a query something like...
With Results As
(
Select Empno, Ename,Sal,
Dense_Rank() Over (Order by Sal Desc) As DenseRank
)
Select * from Results where Results.DenseRank<=5
Note: Make sure to use dense rank because it won't skip the ranks when there is repeated data.
I hope it helps. Thank You. ????