0

我试图展示收入至少是其主管收入的 25% 的员工。到目前为止,我有一个可以显示主管本身的子查询代码,但我不确定如何“获取”主管工资:

SELECT TOP (100) PERCENT firstname + ' ' + lastname        AS Employee, 
                         id, 
                         jobtitle                          AS [Job Title], 
                         Str(Round(salary / 12, 2), 12, 2) AS [Monthly Salary] 
FROM   employeetable 
WHERE  ( id IN (SELECT supervisor 
                 FROM   employeetable 
                 WHERE  ( supervisor IS NOT NULL )) ) 
ORDER  BY lastname, 
          firstname 
4

1 回答 1

1

-- 一、找员工和主管

select emp.id,emp.Salary,Sup.SuperVisor,Sup.Salary
from employeetable emp
join employeetable Sup on emp.supervisor=Sup.id

现在添加 where 子句

where emp.Salary >= .25 * Sup.Salary

消除担任主管的人

and emp.id not in (select distinct supervisor from employeetable)
于 2013-03-20T22:36:11.933 回答