declare @Tab table(a varchar(10),b datetime) insert @tab select 'w','2005-10-1' union all select 'w','2005-09-20' union all select 'd','2003-01-01' union all select 'd','2002-10-05'select a,min(b)as b from @tab group by a 結果:a b ---------- ------------------------------------------------------ d 2002-10-05 00:00:00.000 w 2005-09-20 00:00:00.000
--上面写错了。 declare @tab table(A varchar(20),B datetime)insert @tab values('w','2005-10-1') insert @tab values('w','2005-09-20') insert @tab values('d','2003-01-01') insert @tab values('d','2002-10-05') select A,min(B) from @tab group by A--jieguo d 2002-10-05 00:00:00.000 w 2005-09-20 00:00:00.000
或者: select a,convert(varchar(10),min(b),20)as b from @tab group by a 結果: a b ---------- ---------- d 2002-10-05 w 2005-09-20
insert @tab select 'w','2005-10-1'
union all select 'w','2005-09-20'
union all select 'd','2003-01-01'
union all select 'd','2002-10-05'select a,min(b)as b from @tab group by a
結果:a b
---------- ------------------------------------------------------
d 2002-10-05 00:00:00.000
w 2005-09-20 00:00:00.000
declare @tab table(A varchar(20),B datetime)insert @tab values('w','2005-10-1')
insert @tab values('w','2005-09-20')
insert @tab values('d','2003-01-01')
insert @tab values('d','2002-10-05')
select A,min(B) from @tab group by A--jieguo d 2002-10-05 00:00:00.000
w 2005-09-20 00:00:00.000
select a,convert(varchar(10),min(b),20)as b from @tab group by a
結果:
a b
---------- ----------
d 2002-10-05
w 2005-09-20