数据如下:
A列    B列
A      1       
B      32
C      11
D      22
E      6
A      33
B      111
F      2我要的结果是去除重复的A列值,而且B列最小的保留,然后排序显示出来
结果如下:
A列    B列
A      1
F      2
E      6
C      11
D      22
B      32

解决方案 »

  1.   

    select A,min(B) as B from tablename
    group by A
    order by b
      

  2.   

    select A ,min(B) B
    from table
    group by A
      

  3.   


    with tmp as
    (
    select 'A' cola, 1 colb from dual union all   
    select 'B' cola, 32 colb from dual union all
    select 'C' cola, 11 colb from dual union all
    select 'D' cola, 22 colb from dual union all
    select 'E' cola, 6 colb from dual union all
    select 'A' cola, 33 colb from dual union all
    select 'B' cola, 111 colb from dual union all
    select 'F' cola, 2 colb from dual
    )
    select cola,min(colb) from tmp
    group by cola
    order by 2;COLA  MIN(COLB)
    ---- ----------
    A             1
    F             2
    E             6
    C            11
    D            22
    B            32
      

  4.   

    create table testA(
     A varchar2(10), B number);
     
     insert into testA 
     select 'A',1 from dual union all 
     select 'B',32 from dual union all
     select 'C',11 from dual union all
     select 'D',22 from dual union all
     select 'E',6 from dual union all
     select 'A',33 from dual union all
     select 'B',111 from dual union all
     select 'F',2 from dual;
     
     select * from (select A,B,rank() over(partition by A order by B) n from testA) tt where tt.n<=1 order by tt.B;