简体   繁体   中英

select max record for each employee

I've got an employee rates table in MS Access. I would like to select the latest/max rates record for each employee:

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

How do I select records 2 and 4?

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

well latest vs max rates are 2 different concepts. This should get you the latest rate for the employee.

If you want latest do something like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM