我希望结果显示每个雇主的最低和最高工资组,请参阅下文。
作品
Employer Employee Max Min
A B Y
A C Y
N K Y
N P Y
有什么想法吗?非常感谢。
干杯, 本
答案 0 :(得分:0)
这个怎么样?这不完全是你要求的,但应该做得很好:)
SELECT w.*,
(SELECT employee_name FROM works WHERE employer_name = w.Employer AND salary = w.Min AND ROWNUM <= 1) AS EmployeeMin,
(SELECT employee_name FROM works WHERE employer_name = w.Employer AND salary = w.Max AND ROWNUM <= 1) AS EmployeeMax
FROM (
SELECT employer_name AS Employer,
min(salary) AS Min,
max(salary) AS Max
FROM works
GROUP BY Employer
) AS w