2014-02-27 26 views
-1

我有這樣的疑問:SQL代碼

爲每一位員工,獲取他們的第一個,最後一個名字和他們的直接薪酬和第一,姓氏和工資主管只限於那些超過主管的員工。

我能夠調出的第一個名字,姓氏,以及員工和主管的薪水,但我有完成的代碼只讓比他們的上司更多員工的困難。下面是代碼,我迄今:

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; 

任何人都知道我可以完成這個代碼,只收到做出比他們的上司更多的員工?

+0

爲什麼你用'mysql-workbench'和'mysql-error-1064'來標記這個?你是否真的遇到了這個錯誤,或者你只需​​要幫助完成查詢? – DCoder

+0

看起來它應該被標記爲「help-me-do-my-homework」,而不是...... – CBroe

回答

0
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; 
1

我認爲這是在您的查詢,這是我在此查詢已經改變,以及回答您的難度稍有不慎(e.super_ssn = s.ssn)。

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;