我将这些表格包含以下列:
Employee24( EMPLOYEEID, FIRSTNAME, LASTNAME, GENDER, JOBROLES);
Salary25( EMPLOYEEID, SALARYID, JOBROLES, BASICSAL, ALLOWANCES);
显示与职位规模相关的薪资最高和最低的员工的名字和姓氏
SELECT *
FROM EMPLOYEE24
WHERE EMPLOYEEID IN (SELECT EMPLOYEEID, JOBROLES FROM SALARY25 GROUP BY JOBROLES));
答案 0 :(得分:1)
此查询获取员工ID。我会让你弄清楚如何获得这些名字:
select s.employeeid
from (select s.*, min(basicsal) over (partition by jobrole) as min_bs,
max(basicsal) over (partition by jobrole) as max_bs
from salary25 s
) s
where basicsal in (min_bs, max_bs);
答案 1 :(得分:0)
您可以使用JOIN
表执行Salary25
并执行聚合:
select e.firstname, e.lastname,
s.HighestSal, s.LowestSal, e.jobroles
from Employee24 e inner join
(select employeeid, max(basicsal) as HighestSal, min(basicsal) as LowestSal
from salary25
group by jobrole
) s
on s.jobrole = e.jobrole;
但是,上述查询根据BASICSAL
计算工资,您可能还需要ALLOWANCES
。因此,您可以相应地更改公式。