选择每位员工的最大记录

时间:2014-05-09 14:37:38

标签: sql ms-access

我在MS Access中有一个员工费率表。我想为每位员工选择最新/最高费率记录:

ID(Autonumber)   
EmployeeID
EmployeeRate

So for example for employee nr 3 there would be
ID(Autonumber)   EmployeeID    EmployeeRate
1                3             100.00
2                3             150.00
3                10            110.00
4                10            160.00

如何选择记录2和4?

2 个答案:

答案 0 :(得分:0)

SELECT  a.EmployeeID, MAX(a.EmployeeRate)
FROM YourTable AS a
GROUP BY a.EmployeeID;

答案 1 :(得分:0)

最新与最高费率是两个不同的概念。这应该可以为您提供最新的员工费率。

如果你想要最新做这样的事情

select EmployeeID, EmployeeRate from YourTable a
join (select EmployeeID as EmployeeID , max(id) as id from YourTable group by EmployeeID) b on b.id=a.id