我的查询有问题。
我有一个名为EMPLOYEE的表,我有字段NAME,YEAR和STATUS。
每位员工都有几年和几个地位,但我需要最近一年的状态。
如何获取该数据?
答案 0 :(得分:1)
这应该这样做:
SELECT e.[Name],
e.[Year],
e.[Status]
FROM employee AS e
INNER JOIN
(
SELECT [Name],
MAX([Year])
FROM employee
GROUP BY [Name]
) AS m ON e.[Name] = m.[Name]
AND e.[Year] = m.[Year];