create table ai (id int, Aid int, times smalldatetime)
insert into ai select 1, 2, '2003-09-29'
insert into ai select 2, 4, '2003-09-28'
insert into ai select 3, 3, '2003-09-29'
insert into ai select 4, 2, '2003-09-26'
--把aid一样times最小的排出来
select *
from ai as a
where times in(
select top 1 times from ai where aid=a.aid order by times)
order by id
----把aid一样times最大的排出来
select *
from ai as a
where times in(
select top 1 times from ai where aid=a.aid order by times desc)
order by id