sql

select distinct * from 表

解决方案 »

  1.   

    select * from 表名 group by id,a
      

  2.   

    好象用sql不行啊,除非用临时表什么的
      

  3.   

    select id,a,max(isnull(c,'')) from table group by id,a
      

  4.   

    要加个别名:
    select id,a,max(isnull(b,'')) b from table group by id,a
      

  5.   

    上面说的不对,我做了个实验,比如id不都是1,上面两个说的都不对
    create table #hhh
    (id int,
    a varchar(100),
    b varchar(100)
    )
     
    insert into #hhh values ('1','a1','E')
    insert into #hhh values ('2','a1','')
    insert into #hhh values ('3','a2','E')
    insert into #hhh values ('4','a3','')
    --select top 1 id,a,b from #hhh group by a,b,id
    --select id,a,b from #hhh group by a,b,id
    --select distinct a from #hhh 
    select id,a,max(isnull(b,'')) from #hhh group by id,a
    drop table #hhh继续,我想不出了
      

  6.   

    那就是 与id 无关了?
    那就直接group  by a ,id用子查询选出来。
      

  7.   

    select distinct * from 表
      

  8.   

    select distinct A,id,b  from 表
      

  9.   

    select id,a,min(b) as b from tablename group by id,a
      

  10.   

    建议生成一张临时表,添加字段序号,然后再查询。
    select IDENTITY(int, 1,1) AS ID_Num,* into newtable from tableselect id,a,b from newtable 
    where ID_Num in (select min(ID_Num) from newtable group by a)
      

  11.   

    这个已经符合题意了:select distinct A,Id,B  from 表
      

  12.   

    create table #hhh
    (id int,
    a varchar(100),
    b varchar(100)
    )
     
    insert into #hhh values ('1','a1','E')
    insert into #hhh values ('2','a1','')
    insert into #hhh values ('3','a2','E')
    insert into #hhh values ('4','a3','')
    --select top 1 id,a,b from #hhh group by a,b,id
    --select id,a,b from #hhh group by a,b,id
    --select distinct a from #hhh 
    select distinct A,Id,B  from #hhh
    --select id,a,max(isnull(b,'')) from #hhh group by id,a
    drop table #hhh--结果:
    a1 1 E
    a1 2
    a2 3 E
    a3 4