我正在努力展示至少占其主管制作成果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
答案 0 :(得分: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)