现有一表,里面有多个重复的纪录,如
          a         b
         1         A
         1         A
         2         B
         2         B
         
我现在要的是
          1          A
         2          B
就是把重复的去掉,请各位大侠指教!

解决方案 »

  1.   


    select distinct a,b  from  tb
      

  2.   

    上面说的不是很明白,这个表有十几个字段,我不能一个一个写distinct a,b,c,d....
    有没有其他的方法啊?
      

  3.   


    select distinct t.a,t.b
    from 
    (select '1' as a,'A' as b from dual
    union all
    select '1','A'  from dual
    union all
    select '2','B' from dual
    union all
    select '2','B' from dual )t--------------------------------
        A B
    1 1 A
    2 2 B
      

  4.   

    一共有十几个字段,只有一个字段不重复,其他的都重复。
              a      b        c         d          e         
             100     2         2         2          A             
             101     2         2         2          A
             102     3         3         3          B
             103     3         3         3          B
             104     3         3         3          B
    上面表中除了a字段不同外,我想是以e字段分组,去除重复的
            上面我想得到分组后
        100     2         2         2          A  
        102     3         3         3          B
    也就是说分组后我只想要其中一组,也就是以e分组后A中有两条吗,除了a字段都是一样的,我只要其中一条纪录就行
    B也一样,我只要其中一条纪录就行,因为除了a字段都是重复的。就是这个意思!
     
      

  5.   

    对于LZ提供的数据及结果:select min(t.a) a ,t.b,t.c,t.d,t.e
    from 
    (select '100' as a,'2' as b,'2' as c,'2' as d,'A' as e from dual
    union all
    select '101','2','2','2','A'  from dual
    union all
    select '102','3','3','3','B'  from dual
    union all
    select '103','3','3','3','B'  from dual
    union all
    select '104','3','3','3','B'  from dual
    )t
    group by t.b,t.c,t.d,t.e------------------------------------------
        A B C D E
    1 100 2 2 2 A
    2 102 3 3 3 B
      

  6.   

    to LZ:那样写只是简单做个例子,省略了建表,创建数据,对于你来说直接from你的table就行,当然各栏位也要对应的上-----------------------
    --建表
    create table aaatb(
    a varchar2(10),
    b varchar2(10),
    c varchar2(10),
    d varchar2(10),
    e varchar2(10)

    -----------------------
    --创建测试数据
    insert into aaatb
    select '100' as a,'2' as b,'2' as c,'2' as d,'A' as e from dual
    union all
    select '101','2','2','2','A'  from dual
    union all
    select '102','3','3','3','B'  from dual
    union all
    select '103','3','3','3','B'  from dual
    union all
    select '104','3','3','3','B'  from dual--------------------------------------------
    --执行SQL
    select min(t.a) a ,t.b,t.c,t.d,t.e
    from  aaatb t
    group by t.b,t.c,t.d,t.e---------------------------------------------
    --删除表
    drop table aaatb---------------------------------------------
    --结果如下--
        A B C D E
    1 100 2 2 2 A
    2 102 3 3 3 B
      

  7.   


    select * from (
    select row_number()over (partition by e order by a)S ,a,b,c,d,e
    from theTab 
    ) where S=1
      

  8.   

    select min(t.a)over(partition by t.b,t.c,t.d,t.e  ) a ,t.b,t.c,t.d,t.e--可改为这样
    from  aaatb t
    group by t.b,t.c,t.d,t.e
      

  9.   

    select  序号=row_number()over(order by t.b), min(t.a)over(partition   by   t.b,t.c,t.d,t.e     )   a   ,t.b,t.c,t.d,t.e--可改为这样 
    from     aaatb   t 
    group   by   t.b,t.c,t.d,t.e 
      

  10.   

    select min(a) a ,e,b,c,d from test group by b,c,d,e
    ---------执行结果---------------------------------------
        A E B C D
    1 100 A 2 2 2
    2 102 B 3 3 3