Group Wise Top Salary Using ROW_NUMBER
Group Wise Top Salary Using ROW_NUMBER
Topic Introduction: In this tutorial, we will discuss Group Wise Top Salary using ROW_NUMBER .. Over Partition By. using this we can find out group-wise the highest or lowest n number here will be shown how to find out department-wise top 3 height salary paid employees by a query from HR schema.
find out the top 3 highest salaries paid to employees |
SQL Query to find out the top 3 highest salaries paid to employees
select department_name,last_name,salary,serialfrom(select department_name,last_name,salary,row_number ()over (partition by department_nameorder by department_name asc, salary desc)serialfrom departments d, employees ewhere d.department_id=e.department_id)where serial<=3;
SQL Query to find out the lowest 3 salaries paid to employees
It can be Department wise the lowest 3 salaries paid employees. for this, we just need to modify the above query on order by clause salary desc to salary asc.
For Example:
select department_name,last_name,salary,serialfrom(select department_name,last_name,salary,row_number ()over (partition by department_nameorder by department_name asc, salary asc)serialfrom departments d, employees ewhere d.department_id=e.department_id)where serial<=3;
How to find the third or náµ—Ê° maximum salary from the salary table?
select department_name,last_name,salary,serial
from(
select department_name,last_name,salary
,row_number ()
over (partition by department_name
order by department_name asc, salary asc)
serial
from departments d, employees e
where d.department_id=e.department_id
)
where serial = 3;
No comments