如:id time
1 2010-10-9
1 2010-10-20
1 2010-11-10
2 2010-11-11
2 2010-11-12
3 2010-11-18
3 2010-10-8
取得每个Id号最后时间段的数
1 2010-10-9
1 2010-10-20
1 2010-11-10
2 2010-11-11
2 2010-11-12
3 2010-11-18
3 2010-10-8
取得每个Id号最后时间段的数
go
insert #tb
select 1,'2010-10-9' union all
select 1,'2010-10-20' union all
select 1,'2010-11-10' union all
select 2,'2010-11-11' union all
select 2,'2010-11-12' union all
select 3,'2010-11-18' union all
select 3,'2010-10-8'
go用max()函数select id,max(time) from #tb group by id用子查询select * from #tb t where time=(select max(time) from #tb where id=t.id)