SQL code for retrieving salaries of employees who make more than their supervisor

StackOverflow https://stackoverflow.com//questions/22078866

  •  24-12-2019
  •  | 
  •  

سؤال

I have this question:

For each Employee, retrieve their first, last name and Salary and the first, last name and Salary of their immediate supervisor Only for those Employees who make more than their Supervisor.

I am able to bring up the first name, last name, and salary of the employees and the supervisors, but I am having difficulty with completing the code for only the employees that make more than their supervisor. Here is the code that I have thus far:

select distinct e.fname, e.lname, e.salary, s.fname, s.lname, s.salary 
from employee e, employee s 
where e.super_ssn = s.super_ssn;

Anyone know how I can complete this code and only receive the employees that make more than their supervisor?

لا يوجد حل صحيح

نصائح أخرى

I think there is a slight mistake (e.super_ssn = s.ssn) in your query, which I have changed in this query as well as the answer to your difficulty.

select distinct e.fname, e.lname, e.salary, s.fname, s.lname, s.salary 
from employee e, employee s 
where e.super_ssn = s.ssn and e.salary > s.salary;
    select distinct e.fname, e.lname, e.salary, s.fname, s.lname, s.salary from employee e, employee s where e.super_ssn = s.super_ssn and e.salary>s.salary;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top