thanks remote_peng 如果co2是varchar类型呢? ====================co2是varchar类型不會影響的 create table #test(aa varchar(10), bb varchar(2) ) insert into #test select 'aa','2' union select 'aa','1' union select 'bb','4' union select 'bb','3' select aa,min(bb) from #test group by aa drop table #test
对,varchar不影响的.如果想的到最小的,可以用楼上写的或者是我写的select aa,min(bb) from #test group by aaselect co1,co2 from #tem A Where co2 In (Select Min(co2) from #tem Where co1=A.co1) 如果是想得到第一个,可以这样:select co1,co2 from #tem A Where co2 In (Select TOP 1 co2 from #tem Where co1=A.co1)
如果co2是varchar类型呢?
如果co2是varchar类型,是想得到最小的co2还是每个co1最小的co2??
每个co1最小的co2,最好是能够取得每个col出现的第一个co2
如果co2是varchar类型呢?
====================co2是varchar类型不會影響的
create table #test(aa varchar(10),
bb varchar(2)
)
insert into #test
select 'aa','2' union
select 'aa','1' union
select 'bb','4' union
select 'bb','3' select aa,min(bb) from #test group by aa
drop table #test
如果是想得到第一个,可以这样:select co1,co2 from #tem A Where co2 In (Select TOP 1 co2 from #tem Where co1=A.co1)