但仅限于他们在建筑400,402或405工作
Select fname, lname, dept
from Employees
where in building=400
and building=402
and building =405;
所以我发现平均然后放置数字在sql中的构建,或者,我是否使用AVG()函数来找到答案?我想使用子查询,但不知道如何,帮助!
答案 0 :(得分:1)
Select fname, lname, dept
from Employees
where building in (400,402,405) and salary > (select avg(salary) from Employees where building in (400, 402, 405));
“薪水”是员工赚取多少的列。
另外,你的陈述是错的,我已经为你编辑了。
超出主题问题: 您是否在人力资源部门工作,并试图寻找一些能比其他人更赚钱的高管来解雇他们以降低公司成本?
答案 1 :(得分:1)
听起来像是:
SELECT fname
,lname
,dept
FROM Employees a
INNER JOIN
(SELECT Building
,AVG(Salary) BuildingAvgSalary
FROM Empoyees
WHERE Building IN (400,402,405)
GROUP BY Building) b ON a.Building = b.Building
WHERE a.Salary > b.BuildingAvgSalary