Customers Earn More than their Managers SQL

By   Tewodros   Date Posted: Oct. 12, 2021  Hits: 887   Category:  Database   Total Comment: 0             A+ A-


side

Given a list of employees and their corresponding managers, we would like to find those customers who earn less than their managers.

CustomerIDNameSalaryManager
1Dave10002
2Peter2000 
3Salem30002
4Doe50002

In this example, we can see that Peter is the manager of three customers (Dave, Salem and Doe). But only Salem and Doe earn more than him. 

Solution.

In this kind of situation, we can see that the manger is also an employee and it is stored in the same employee table. Therefore, we can have a self join here and check if a certain employee e make more money than his manager m. 

select e.Name Employee

from Employee e , Employee m

where e.Manager = m.Id and

e.salary > m.Salary and

e.Manager is not null

 

 


Tags



Back to Top



Related Blogs






Please fill all fields that are required and click Add Comment button.

Name:*
Email:*
Comment:*
(Only 2000 char allowed)


Security Code:* qorrif

Back to Top