开发者

MS Access query - select most recent date

I have a query 开发者_如何学编程I'm designing which grabs data from multiple different tables. In MS Access 2010, how would I create one of the query columns so that it returns the most recent date out of a series of dates, for each user in the table:

Sample data from table:

userid: | appointment:
000001  | 05/10/2009
000001  | 05/10/2010
000001  | 05/11/2010
000002  | 05/12/2009
000002  | 30/12/2010

expected output for field query:

userid:  | appointment:
000001   | 05/11/2010
000002   | 30/12/2010


SELECT userid, Max(appointment) AS most_recent
FROM YourTable
GROUP BY userid;


SELECT B.Job_Emp_ID, B.JobTitle, B.Salary,B.AssignmentDate FROM tbl_Emp_Job_Assignment as B INNER JOIN tbl_Emp_Job_Assignment as A ON (B.Job_Emp_ID=A.Job_Emp_ID and B.AssignmentDate>A.AssignmentDate) GROUP BY B.Job_Emp_ID, B.JobTitle,B.Salary, B.AssignmentDate;

This works Great!It gives the Latest job assignment and Assignment Date.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜