0

我有两个表,JobTableEmployeeTable带有以下数据:

员工表:

EmpId    Salary
1          10
2          20
3          30
4          40
5          50
6          60

工作表:

JobId    EmpId
A          1
A          2
B          3 
B          4
C          5
C          6

我需要一个 SQL 语句,它将返回EmpId每个 Job 的最低工资的 Employee 。

4

2 回答 2

1

您可以RANK()像这样使用该功能:

WITH ranked AS (
  SELECT
    j.JobId,
    e.EmpId,
    e.Salary,
    RANK() OVER (PARTITION BY j.JobId ORDER BY e.Salary) AS rnk
  FROM JobTable j
  INNER JOIN EmployeeTable e ON j.EmpId = e.EmpId
)
SELECT
  JobId,
  EmpId,
  Salary,
FROM ranked
WHERE rnk = 1
于 2012-05-30T08:18:50.050 回答
0

嗯,试试这个:

SELECT st.EmpID, min(st.salary) 
FROM SalaryTable st INNER JOIN JobTable jt ON st.EmpID=jt.EmpID 
WHERE jt.JobID = 'A' 
GROUP BY st.EmpID
于 2012-05-30T02:21:33.990 回答