我的问题是:列出薪水大于平均工资的所有员工,并显示差异有多大。
SELECT staffname
FROM staff
WHERE salary >= (SELECT Avg(salary)
FROM staff)
AND (SELECT Max(salary) AS Max_Salary,
Avg(salary) AS Avg_Salary
FROM staff
WHERE salary = max_salary - avg_salary)
大于平均工资的薪水很快就会出来,但我无法证明差异有多大。
答案 0 :(得分:2)
SELECT staffname, staff.salary - avg.salary
FROM staff, (SELECT AVG(salary) salary FROM staff) avg
WHERE staff.salary > avg.salary
答案 1 :(得分:0)
Select Count(*), (Select Avg(Salary) From Staff)
From Staff
Where Salary > (Select Avg(Salary) From Staff);