declare @t table (n int,c int,p datetime)insert into @t select 0,1,'2005-12-12' union all select 1,1,'2005-11-10' union all select 2,1,'2005-12-20' union all select 0,2,'2005-10-11' union all select 1,2,'2005-10-12' union all select 2,2,'2005-10-13'select 编号=a.c,最小日期=a.p from @t a where not exists (select * from @t b where a.c=b.c and a.p>b.p) 编号 最小日期 ----------- ------------------------------------------------------ 1 2005-11-10 00:00:00.000 2 2005-10-11 00:00:00.000
union all select 1,1,'2005-11-10'
union all select 2,1,'2005-12-20'
union all select 0,2,'2005-10-11'
union all select 1,2,'2005-10-12'
union all select 2,2,'2005-10-13'select 编号=a.c,最小日期=a.p
from @t a where not exists (select * from @t b where a.c=b.c and a.p>b.p)
编号 最小日期
----------- ------------------------------------------------------
1 2005-11-10 00:00:00.000
2 2005-10-11 00:00:00.000