select * from yourtable where 时间 in(select max(时间) 时间 from 表 group by 姓名)
select A.ID,A.姓名,A.时间 from A join (select 姓名,max(时间) as 时间 from A group by 姓名) B on A.姓名=B.姓名 and A.时间=B.时间
如表A: ID 姓名 时间 1 lee 2003-08-10 2 lee 2003-08-11 3 lee 2003-08-12 4 chan 2003-08-10 5 chan 2003-08-15 6 chan 2003-08-16如何按姓名分类只取出时间最大的记录?如上表只取出3和6两条记录! select * from [table] as tmp where 时间=(select max(时间) from [table] where tmp.姓名=姓名)
group by 姓名
A.姓名=B.姓名 and A.时间=B.时间
ID 姓名 时间
1 lee 2003-08-10
2 lee 2003-08-11
3 lee 2003-08-12
4 chan 2003-08-10
5 chan 2003-08-15
6 chan 2003-08-16如何按姓名分类只取出时间最大的记录?如上表只取出3和6两条记录!
select * from [table] as tmp where 时间=(select max(时间) from [table] where tmp.姓名=姓名)