select a,b,c=min(c),c=min(d) from tablename group by a,b
或用:临时表.
      select id=identity(int,1,1),* into #tmp from tablename
     select * from  from #tmp----------查非id字段
     where id in (select min(id) from #tmp group by a,b)
     drop table #tmp

解决方案 »

  1.   

    select a,b,c=min(c),c=min(d) from tablename group by a,b
    或用:临时表.
          select id=identity(int,1,1),* into #tmp from tablename
         select * from  from #tmp----------查非id字段
         where id in (select min(id) from #tmp group by a,b)
         drop table #tmp
      

  2.   

    --建立测试环境      
    Create table X
    (a Int,
    b varchar(10),
    c varchar(10),
    d varchar(10),
    )
    Insert X values(1,'f','s','l')
    Insert X values(1,'g','f','k')
    Insert X values(1,'f','s','l')
    Insert X values(2,'z','n','k')
    Insert X values(2,'z','n','k')
    Select * from X
    --测试
    Select a,b,Min(c) As c,Min(d)As d from X Group By a,b Order By a,b--删除测试环境
    Drop table X
      

  3.   

    alter table x add sid int identity(1,1)
    go
    select *
    from x a
    where not exists(select 1 from x where a=a.a and b=a.b and sid<a.sid)
    go
    alter table x drop column sid
      

  4.   

    chinaandys(降龙十八炒):
    多了一個from﹗﹗