如果表中的字段都是数字型的可以用 select a,max(b) b,max(c) c from aa group by a
select * from aa where a in(select distinct(a) from aa)
如果(a,b)不重复select * from tablename x where b=(select min(b) from tablename where a=x.a)
否则,只有这样才保险select *,IDENTITY(int,1,1) as id into #t from tablenameselect a,b,c from #t x where not exists ( select 1 from #t where a=x.a and id<x.id )
select top 1 * into #a from aa delcare @a as varchar(20) delete from #a declare cur_sor cursor for select distinct a from aa open cur_sor open cur_sor fetch next from cur_sor into @a while @@fetch_status = 0 begin insert into #a select top 1 * from aa where a = @a fetch next from cur_sor into @a end 这个办法虽然麻烦,但可以实现
select a,max(b) b,max(c) c from aa
group by a
where b=(select min(b) from tablename where a=x.a)
into #t from tablenameselect a,b,c from #t x
where not exists (
select 1 from #t where a=x.a and id<x.id
)
delcare @a as varchar(20)
delete from #a
declare cur_sor cursor for
select distinct a from aa
open cur_sor
open cur_sor
fetch next from cur_sor into @a
while @@fetch_status = 0
begin
insert into #a
select top 1 * from aa where
a = @a
fetch next from cur_sor into @a
end
这个办法虽然麻烦,但可以实现